Python - Variable
A variable must have a short name (like a and b) or a more descriptive name (age, carname, total_volume).
Rules for Python variables:
· The variable name only start with a letter or the underscore character.
· The variable name cannot start with a number.
· The variable name must only contain alpha-numeric characters and underscores.
· Variable names are case-sensitive (name, Name and NAME are three different variables).
Variables are case sensitive.
Unlike other programming languages Python has no command for declaring a variable.
A variable is created when you first assign a value to it.
x = 5 # x is the type of int
x ="Tripti" # x is the type of str
You can also use the
+ character to add a variable to another variable and to combine both text and a variable.
x = "My name is "
y = "sana"
z = a + b