Python is not “statically typed”. We do not need to declare variables before using them, or declare their type. A variable is created the moment we first assign a value to it.
45 1456.8 John
Rules for creating variables in Python are same as they are in other high-level languages. They are:
a) A variable name must start with a letter or the underscore character.
b) A variable name cannot start with a number.
c) A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
d) Variable names are case-sensitive (name, Name and NAME are three different variables).
e) The reserved words(keywords) cannot be used naming the variable.
Assigning a single value to multiple variables:
Also Python allows to assign a single value to several variables simultaneously.
10 10 10
Assigning a different values to multiple variables:
1 20.2 GeeksforGeeks
Can we use same name for different types?
If we use same name, the variable starts referring to new value and type.
How does + operator work with variables?
Can we use + for different types also?
No using for different types would produce error.
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Creating objects (or variables of a class type):
Please refer Class, Object and Members for more details.
cse cse 101 cse
- Python Scope of Variables
- Private Variables in Python
- Global and Local Variables in Python
- Python | Extract key-value of dictionary in variables
- Python Program to Swap Two Variables
- Tracing Tkinter variables in Python
- Class or Static Variables in Python
- Python | Unpack whole list into variables
- Python - Pearson Correlation Test Between Two Variables
- Python - Construct variables of list elements
- How to assign values to variables in Python and other languages
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Inserting variables to database table using Python
- How are variables stored in Python - Stack or Heap?
- Swap two variables in one line in C/C++, Python, PHP and Java
- Python | Difference between Pandas.copy() and copying through variables
- Python | Assign multiple variables with list values
- Python program to find number of local variables in a function
- R - Variables
- ES6 | Variables
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.