If we want to give a name to a variable, there’re some rules
to follow.
1.
Variable name must be composed of upper case
letters, lower case letters, digits and characters (underscore).
2.
Variable name must begin with a letter.
3.
Underscore character is also a letter.
4.
Variables with same meaning but, with different
upper case & lower case letters are treated as two different variables.
Example:
THETEXT
thetext
theText
Given above three different variables.
5.
Variable name must not be any of Python’s reserved
word.
NOTE
The PEP
8 – Style Guide for Python Code recommends the following naming convention
for variables & functions in Python.
1.
Variable names should be lowercase with words
separated by underscores to improve readability.
Example: my_variable
2.
Function names follow the same convention as
variable names.
Example: my_function
3.
It’s also possible to use mixed case, but only
in contexts where that’s already the prevailing style, to retain backwards
compatibility with the adopted convention.
Example: myVariable
Keywords
Given below the reserved keywords in Python. They are
reserved because we mustn’t use them as names, neither for the variables, nor
functions. The meaning of the reserved word is predefined, and mustn’t changed
any way.
['False', 'None', 'True', 'and',
'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else',
'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while',
'with', 'yield']
A variable comes into existence as a result of assigning a
value to it. Unlike in other languages, we don’t need to declare it in any
special way. If you assign any value to a non-existent variable, the variable
will be automatically created. We don’t need to do anything else.
The creation is very simple, just use the name of the
desired variable then the equal sign (=) and the value you want to put into the
variable.
No comments:
Post a Comment