Python Variables
In most of the programming languages a variable is a named location used to store data in the memory. Each variable must have a unique name called identifier. It is helpful to think of variables as container that hold data which can be changed later throughout programming.
Note: In Python we don't assign values to the variables, whereas Python gives the reference of the object (value) to the variable.
Variable Declaration
In Python, variables do not need declaration to reserve memory space. The variable declaration or variable initialization happens automatically when we assign a value to a variable.
Assigning value to a Variable
You can use the assignment operator = to assign the value to a variable.
For example:
var = "Python is Awesome"
print(var)
Copy
Note: Copy and Paste Code into Compiler
Open Compiler
Note : Python is a type inferred language, it can automatically infer a String and declare another String.
For example:
var = "Python is Awesome"
# assigning a new value to var
var = "I Love Python..."
print(var)
Copy
Note: Copy and Paste Code into Compiler
Open Compiler
Valid Variable Names
The naming of variables follows the more general concept of an identifier. A Python identifier is a name used to identify a variable, function, class, module or other object.
A variable name and an identifier can consist of the uppercase letters "A" through "Z", the lowercase letters "a" through "z" , the underscore _ and, except for the first character, the digits 0 through 9. Python 3.x is based on Unicode. This means that variable names and identifier names can additionally contain Unicode characters as well. But in Python 2, identifiers can only be ASCII letters, numbers and underscores.
Identifiers are unlimited in length. Case is significant. The fact that identifier names are case-sensitive can cause problems to some Windows users, where file names are case-insensitive for example.
PreviousNext
In most of the programming languages a variable is a named location used to store data in the memory. Each variable must have a unique name called identifier. It is helpful to think of variables as container that hold data which can be changed later throughout programming.
Note: In Python we don't assign values to the variables, whereas Python gives the reference of the object (value) to the variable.
Variable Declaration
In Python, variables do not need declaration to reserve memory space. The variable declaration or variable initialization happens automatically when we assign a value to a variable.
Assigning value to a Variable
You can use the assignment operator = to assign the value to a variable.
For example:
var = "Python is Awesome"
print(var)
Copy
Note: Copy and Paste Code into Compiler
Open Compiler
Note : Python is a type inferred language, it can automatically infer a String and declare another String.
For example:
var = "Python is Awesome"
# assigning a new value to var
var = "I Love Python..."
print(var)
Copy
Note: Copy and Paste Code into Compiler
Open Compiler
Valid Variable Names
The naming of variables follows the more general concept of an identifier. A Python identifier is a name used to identify a variable, function, class, module or other object.
A variable name and an identifier can consist of the uppercase letters "A" through "Z", the lowercase letters "a" through "z" , the underscore _ and, except for the first character, the digits 0 through 9. Python 3.x is based on Unicode. This means that variable names and identifier names can additionally contain Unicode characters as well. But in Python 2, identifiers can only be ASCII letters, numbers and underscores.
Identifiers are unlimited in length. Case is significant. The fact that identifier names are case-sensitive can cause problems to some Windows users, where file names are case-insensitive for example.
PreviousNext
No comments:
Post a Comment