Editing Python Names

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 54: Line 54:
 
= Avoid Reserved Words =
 
= Avoid Reserved Words =
  
Reserved words are words that are reserved for the language that you are not suppose to use, words like if, else, while, def.  Python will actually throw an syntax error in most cases if you use them.   
+
Reserved words are woods that are reserved for the language that you are not suppose to use, words like if, else, while, def.  Python will actually throw an syntax error in most cases if you use them.   
  
 
There are even more words that you should treat as reserved words, that is do not use them.  These words are ones that other parts of the language may already be using. Suppose that you are doing some math.  Then you might suspect that words like sin, sine, min, max, random might already be in use.  Try to be a bit careful.  In some contexts both n and i are already defined ( i for the imaginary unit, n for a function that forces numerical evaluation )  
 
There are even more words that you should treat as reserved words, that is do not use them.  These words are ones that other parts of the language may already be using. Suppose that you are doing some math.  Then you might suspect that words like sin, sine, min, max, random might already be in use.  Try to be a bit careful.  In some contexts both n and i are already defined ( i for the imaginary unit, n for a function that forces numerical evaluation )  
Line 85: Line 85:
 
= Variables =
 
= Variables =
  
Most programming languages have variables, and Python users often refer to variables, but actually, sort of, '''Python does not have variables''' it has '''names'''.  Is this a difference that makes a difference?  If I say:
+
Most programming languages have variables, and Python users often refer to variables, but actually, sort of, Python does not have variables it has names.  Is this a difference that makes a difference?  If I say:
  
 
<pre>
 
<pre>
Line 94: Line 94:
  
 
Then self.monitor_state has changed or varied, so it must be a variable.  Yes and No.  self.monitor_state is a name and at one time it "pointed to" a value of 1 and later it  "pointed to" a value of 2.  A mutable object is in some ways more like a variable.  I will not say more here, but at some point you might want to investigate this issues because, sometimes, they make a difference.
 
Then self.monitor_state has changed or varied, so it must be a variable.  Yes and No.  self.monitor_state is a name and at one time it "pointed to" a value of 1 and later it  "pointed to" a value of 2.  A mutable object is in some ways more like a variable.  I will not say more here, but at some point you might want to investigate this issues because, sometimes, they make a difference.
You may find this useful: '''[https://www.youtube.com/watch?v=4MCT4WLf7Ac&__s=dibfsizig3wuxjywoekt (26) "Python Oddities Explained" - Trey Hunner (PyCon AU 2019) - YouTube ]''' and '''[https://treyhunner.com/python-oddities/#/3 Python Oddities Explained ]'''
 
  
 
= Class Instance Variables =
 
= Class Instance Variables =

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)