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 74: Line 74:
 
       def display_help():                    # verb like
 
       def display_help():                    # verb like
 
</pre>
 
</pre>
 
 
= Declare at top of Class =
 
 
Actually Python does not have declarations but for me this means do an assignment in __init__ or very nearby and comment the variables.  Sometimes this is a natural part of the initialization, other times it is not, perhaps because the value is not know yet.  In this case assign it to None.
 
 
<pre>
 
    self.live_graph_lines    = None      # lines on the graph, we keep for later updating
 
</pre>
 
= 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:
 
 
<pre>
 
    self.monitor_state  = 1 
 
    # then....       
 
    self.monitor_state  = 2 
 
</pre>
 
 
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)