Python | Variables
In this tutorial you can learn about Variable in python with pythonwithyp, python variable is simple as in other programming language . variable simple means it is a one type of container ,that was contain some value like integer ,float ,string etc
![]() |
PYTHON Variable | pythonwithyp |
Python | Variables
- variable is container of to store a data value
- python can simple declare a variable
- python has not any keyword to declare a variable
Example
x = 5 # variable x store a integer five value
y = "Wel-Come" # variable y store a string value
print (x)
print (y)
Output
5
Wel-Come
Above example show the variable x is contains 5 integer type value and y is contain string type value
Get The type of Variable
type() function used to get the type of variable ,which type of value variable can store data like integer ,string ,float etc
Example
x = 5
y = "Wel-Come"
print( type(x) )
print( type(y) )
Output
<class 'int'> <class 'str'>
Case sensitive
Python variables are Case sensitive ,it means Variable and variable are not same.
Example
a = 5
A = "Wel-Come"
variable A and a not are same , they have different data type
Type Casting
type casting used for to specify the variable with data type
type type casting is a fix to the data type of variable
Example
x = str( 5 ) # "5"
y = int ( 5 ) # 5
z= float ( 5 ) # 5,0
Variable name
Rules for Creating variable Name
- A variable name cannot start with a number it can start with letter or underscore character
- A variable name contain only alpha-numerical characters or underscore
- A variable name are case-sensitive
Example
myvar = "Hello"
my_var = "Hello"
_myvar = "Hello"
Myvar = "Hello"
my_var = "Hello"
MYVAR = "Hello"
myvar 2= "Hello"
Also see