- Variables are referred to “envelop” or “buckets” where information can be maintained and referenced. Like any other programming language Python also uses a variable to store the information...
- Variables can be declared by any name or even alphabets like a, aa, abc, etc...
- Variables can be re-declared even after you have declared them for once...
- Types of variables in Python or Python variable types : Local & Global...
- Declare local variable when you want to use it for current function...
- Declare Global variable when you want to use the same variable for rest of the program...
- To delete a variable, it uses keyword “del”...
- Variables are containers for storing data value / values...
- Python has no command for declaring a variable...
- A variable is created the moment you first assign a value to it...
- Variable do not need to be declared with any particular type...
- A variable can even change type after they have been set...
- Variables are case sensitive...
- String variables can be declared either by using single or double quotes...
- Variable name should not start with numbers...
- A variable name may only contain (0-9), (A-Z), (a-z) and underscore(_)...
- A variable name should not contain spaces...
Data type not specified, Python will automatically finds as integer based on the type of value...
x = 4
print(x)
Variable in small letter (Case Sensitive)...
String given inside double quotes...
a = "Green"
print(a)
Variable in capital letter (Use only for Constant Values)...
String given inside single quotes (Optional)...
A = 'Ragu' print(A)
If you want to specify the data type of a variable, this can be done with casting...
x = str(3) y = int(3) z = float(3) print(x) print(y) print(z)
You can get the data type of a variable with the type() function...
x = 5 y = 3.5 z = "John" print(type(x)) print(type(y)) print(type(z))