2.1 Names and variables
Python is a case sensitive language where 'print' is not equal to 'PRINT' or 'Print'. Those three versions are similar in the meaning to us, but not in the python language. This implys that in naming our varables we must take the case sensitivty feature in consideration, so that it doesn't confuse us or anyone reading the code, hence readability maintained. The keywords in python is may change from time to time, because python is a dynamic language. This is a list of keywords in python.
And exec Not Assert finally or
Break for pass Class from print
Continue global raise def if return
del import try elif in while
else is with except lambda yield
these are reserved words and you cannot use them to name any identifiers. Python keywords are with lower case letters only.
Python like many other programming languages have some similar naming conventions and some other unique naming rules. First of all python is a case sensitive language Among the naming conventions in python the following:
- 'A' , 'b' a single UPPER/lower case.
- 'lowercase' lower case string.
- 'UPPERCASE' UPPER case string.
- 'lower_case' lower case with underscore.
- 'UPPER_CASE' UPPER case with underscore.
- 'MyName' capitalizing the first letter of each word, which called CapWord or CamelCase because of the bumps on its look.
- 'myName' the mixed case.
According to (Van Rossum, G., Warsaw, B., & Coghlan, N., 2001). There are certain naming conventions to be avoided. The 'l' lower case 'el' as single letter name. Because it is hard to distinguish if it's '1' number one or 'eye' upper case letter of 'I', also 'O' upper case 'oh'. Though they are different but in terms or readability, using these letters as single name decreases readability.
Class names should normally use the CapWords convention. The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable. Note that there is a separate convention for built in names: most built in names are single words (or two words run together), with the CapWords convention used only for exception names and built in constants(Van Rossum, G., Warsaw, B., & Coghlan, N., 2001).
The underscore in python carrying different meaning. When an underscore leads the name of an identifier it conveys that its private. Also, in the case of double underscore leading the name of an identifier indicates strongly private identifier. For example:
_age=20
# age is private.
__age=20
# age is a strongly private identifier.
In python like in many other languages the variables comes in a format where a symbolic name associated to the left and its value to the right(Batchelder, N, 2015). For example:
x=24
# And a name can refer to more than or value:
x=24
y=x
# But names can be assigned separately from other names:
x=24
y=x
x= 100
# the value of y is still 24 though we reassigned x to 100.
You may have wondered about the '#' appears in some lines above, these is how we comment in python language. Typically in other languages we use '//' to indicate a comment, which means that the compiler won't execute this part or line of the code.
The size of an integer in python is unlimited. Yet, in the computer world memory is a constraint. Basically, there is nothing in python language that limits the size of your variable integer, but that is technically your memory size.
*some components of this post have been adopted from here