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 | + | 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, | + | 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. | ||
− | |||
= Class Instance Variables = | = Class Instance Variables = |