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
- Private Variables in Python
- Python Scope of Variables
- Python | Extract key-value of dictionary in variables
- Class or Static Variables in Python
- Python Program to Swap Two Variables
- Tracing Tkinter variables in Python
- Python | Unpack whole list into variables
- Global and Local Variables in Python
- Swap two variables in one line in C/C++, Python, PHP and Java
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Python - Construct variables of list elements
- How are variables stored in Python - Stack or Heap?
- How to assign values to variables in Python and other languages
- Inserting variables to database table using Python
- Python | Difference between Pandas.copy() and copying through 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 email@example.com. 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.