Variables are containers for store the date
Python has no command for declaring a variable
- A Variable name must start with a letter or underscore
- a variable name cannot start with a number
- A variable name can only contain alpha-numeric and underscore
- Variable names are case sensitive
- A variable name cannot be any of the python Keywords
|
SYNATAX a = 10 b = "RAMAKRISHNA" print (a) print(b) OUTPUT 10 RAMAKRISHNA
|
In Python, you can store any value in a variable without specifying its type, and change it anytime.
SYNATAX a = 10 A = "RAMAKRISHNA" print (a) OUTPUT RAMAKRISHNA |
CASTING
In python you can declare data types of a variable by using casting
SYNATAX a = int(10) b = str("RAMAKRISHNA") print (a) print(b) OUTPUT 10 RAMAKRISHNA |
String variable can be declare either single quotation or double quotations
SYNATAX a = 'Ramakrishna' b = "RAMAKRISHNA" print (a) print(b) OUTPUT Ramakrishna RAMAKRISHNA |
CASE SENSITIVE
Python variables name are case sensitive
SYNATAX a = 10 A = "RAMAKRISHNA" print (a) print(b) OUTPUT 10 RAMAKRISHNA |
DIFFERENT TYPES OF VARIABLE NAMES
CAMEL CASE
Each word expect the first start with a capital letter
EX: myVariableName = "Ramakrishna"
PASCAL CASE
Each word start with a capital letter
EX: MyVariableName = "Ramakrishna"
SNAKE CASE
Each word separated with underscore
EX: my_variable_name = "Ramakrishna"
ASSIGN MANY VALUES TO VARIABLES
In python allows assign many values to variables in a single line
|
SYNTAX x, y, z = "apple", "graphs", "oranges" print(x) print(y) print(z) OUTPUT apple graphs oranges
|
ONE VALUE IN MULTIBLE VARIABLES
|
SYNTAX X = Y = Z = "apple" print(X) print(Y) print(Z) OUTPUT apple
|
GET THE TYPE
You can get the data type of a variable using type(). function.
SYNTAX a = 10 b = "ramakrishna" c = 10.5 print(type(a)) print(type(b)) print(type(c)) OUTPUT int
str float |