Solution:
Variable Naming Conventions and Rules
You may be noted with algebraic equations, such as the quadratic:
ax² + bx + c = 0
In mathematics, variables are usually single letters like x, y, and z, or Greek symbols like π or θ. Mathematicians mostly exercise variables at the time they don’t know a particular value however are performing towards tracing it. It’s diverse in Python. You should assign a value to a variable before you can employ it, in fact in case that value is zero or empty. For example, I call the variable Guido prior assigning it a value:
>>> Guido
I will get the following error:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'Guido' is not defined
Variable assignment performs left to right.
>>> Guido = 0
Is acceptable. As is:
>>> Guido = ""
And even:
>>> Guido = False
However the following will give you a this error.
>>> 0 = Guido
>>> ‘’ = Guido
>>> False = Guido
The first two gave you an error that peruse:
File "", line 1
SyntaxError: can't assign to literal
However the last one gave you an error that read:
File "", line 1
SyntaxError: assignment to keyword
That’s cause False is a reserved word in Python. It’s what computer scientists note to as a Boolean value, and you can’t exercise it as a variable identifier. There’s a Python module named keyword. It has a function named kwlist. Importing keyword and calling kwlist will return a list of Python’s keywords. Attempt it:
>>> import keyword
>>> keyword.kwlist
Those are all the words you can’t exercise. However that’s okay. At the times it comes to variable names, the sky is the limit! Well, almost. There are few rules you require to follow and few conventions you ought.
The Rules
1. Variables names should begin with a letter or an underscore, such as:
2. The residual of your variable name may compose of letters, numbers and underscores.
The Conventions
Readability is very significant. Which of the following is simpliest to read? I’m expectant you’ll tell the first example.
python_puppet
pythonpuppet
pythonPuppet
Narrative names are very helpful. In case you are writing a program that includes up all of the bad puns made in this book, which do you think is the better variable name?
Avoid employing the lowercase letter ‘l’, uppercase ‘O’, and uppercase ‘I’. Why? reason the l and the I look a lot like each other and the number 1. And O looks a lot like 0.