Variables
Variables are simply a container for storing values.
Create Variables
Python has no key for declaring variables, Variables are created when you assign a value to it.
a = 5
b = "Earth"
print(a)
print(b)
In Python do not need to declare the variables type, variable type automatically assigned when you will assign a value and variables types can be changed after assigning the value.
a = 5 # a is an integer type of variable
b = "Earth" # b is an string type of variable
c = 5.5 # c is an float type of variable
print(a)
print(b)
print(c)
Casting
You can declare the data types of a variables, by using casting. Python have built-in function for declaring the data type. There is lots of casting but we will see only about three.
int()
This is an Python built-in function used for declaringInteger Data Types
.str()
This Pythonstr
Function used to declareString Data Types
.float()
This is anfloat function
used for declaringFloat Data Types
. This function also used for convertingInteger
toFloat
data types.
int() # This is an int function
str() # This is an str function
float() # This is an float function
How To Use Castings in Python
See here in this example we will learn how we can cast an data type by using python built-in function.
a = int(5) # We casting 5 as integer data types to 'a' variable
b = str('Earth') # We casting "Earth" as string data types to 'b' variable
c = float(5.5) # We casting 5.5 as float data types to 'c' variable
print(a)
print(b)
print(c)
Get Data Types
We will learn how to check or get the data types of variables. We will use type()
function to check the data types.
a = 5
print(type(a))
Print Message in Python
print()
this is an function for printing any message in human readable form.
print('Hello')
print(5)