PREV NEXT
Python Variables:
Variable is nothing but container, it holds some data and one data at a time
Single variable hold Single data
Most variables have unique names
To write the variable names, we can use lowercase (a-z), uppercase (A-Z),numbers(0-9) and underscore _
Never use special character while naming variables such as @,$,%.&,! Etc
Don’t Start variable name with numbers
But, we can use the variable name with the combination of alphabets and numbers
Like in other programming language, we can’t declare the variable before going to use that variables
So, we can assign the value to variable directly before we are going to use
So, there is no concept of declaring a variable in python programming
But, we can consider the direct assign value to variable as the variable initialization of that variable
Examples:
Single value Assign to Single Variables:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
x=10 #integer variable y=2.5 #floating variable str_single=’ hai this is my variable’ #string in single quotes str_double=”This is string in double quotes” print x #value is 10 print y #value is 2.5 print str_single #string is hai this is my variable print str_double # This is string in double quotes |
Output:
Single value Assign to Multiple Variables:
1 2 3 4 5 6 7 |
x=y=z=34 print x #value is 34 print y #value is 34 print z #value is 34 |
Output:
Multiple values Assign to Multiple Variables:
1 2 3 4 5 6 7 |
x,y,s=10,2.5,'hai' print x # value is 10 print y # value is 2.5 print s # value is hai |