To create a variable in Python, all you need to do is specify the variable name, and then assign a value to it.
<variable name> = <value>
Python uses = to assign values to variables. There's no need to declare a variable in advance (or to assign a datatype to it), assigning a value to a variable itself declares and initializes the variable with that value. There's no way todeclare a variable without assigning it an initial value.
Variable assignment works from left to right. So the following will give you a syntax error.
You can not use python's keywords as a valid variable name. You can see the list of keywords by:
Rules for variable naming:
1.Variables names must start with a letter or an underscore.
2. The remainder of your variable name may consist of letters, numbers and underscores.
3.Names are case sensitive.
Even though there's no need to specify a data type when declaring a variable in Python, while allocating the necessary area in memory for the variable, the Python interpreter automatically picks the most suitable built-in type for it:
0 Comments