What is Variable in Python
A variable is a label for a location in memory that can be used to hold a value. Unlike other programming languages, python is not strictly typed, i.e. there is no need to declare variables or declare their type before using them.
Rules for creating variables in Python:
- The variable must start with a letter or underscore character.
- The variable name cannot start with a number.
- Only alpha-numeric characters and underscores (A-z, 0-9, and _ ) must be in a variable name.
- Variable names are case-sensitive (name, Name, and NAME are three different variables).
- The reserved words(keywords) cannot be used to name the variable.
Example:
a = 5 b = 'PYTHON' c = 3.09 print(a) print(b) print(c)
Output:
5 PYTHON 3.09
A variable once declared can be re-declared in Python. But the previous data is lost.
Example:
a = 5 print("Before redeclaring: ", a) a = 15.43 print("After redeclaring: ", a)
Output:
Before redeclaring: 5 After redeclaring: 15.43
Subscribe
Login
Please login to comment
0 Discussion