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
- Global and Local Variables in Python
- Class or Static Variables in Python
- How to assign values to variables in Python and other languages
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Swap two variables in one line in C/C++, Python, PHP and Java
- Python | Difference between Pandas.copy() and copying through variables
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- zip() in Python
- try and except in Python
- chr() in Python
- Python | a += b is not always a = a + b
- pow() in Python
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.