A variable is a container for a value. It can be assigned a name, you can use it to refer to it later in the program.
Based on the value assigned, the interpreter decides its data type. You can always store a different type in a variable.
For example, if you store 5 in a variable, later, you can store ‘Balaji’.
1. Python Variables Naming Rules
There are certain rules to what you can name a variable(called an identifier).
Python variables can only begin with a letter(A-Z/a-z) or an underscore(_).
The rest of the identifier may contain letters(A-Z/a-z), underscores(_), and numbers(0-9).
Python is case-sensitive, and so are Python identifiers. Name and name are two different identifiers.
2. Assigning and Reassigning Python Variables
To assign a value to Python variables, you don’t need to declare its type.
You name it according to the rules stated in section 2a and type the value after the equal sign(=).
Like a=3,Bob=7,age=75 etc...
3. Multiple Assignment
You can assign values to multiple Python variables in one statement.
Or you can assign the same value to multiple Python variables.
4. Swapping Variables
Swapping means interchanging values. To swap Python variables, you don’t need to do much.
5. Deleting Variables
You can also delete Python variables using the keyword ‘del’.
Reserved Words (Keywords)
The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be typed exactly as written here:
No comments:
Post a Comment