Contents of this blog:
- Variables
- Data types
- Print statement
- Type conversion
- Input statement
Variables are named memory locations containing value. Variables can store values of different types.
You can assign a value to a variable using a equal sign(=). Eg:- a=10. If you assign a new value to the same variable, previous value will be erased and the variable will contain the new value.
In python, you don’t need to declare the data-type during assigning the variable.
Different Data-types:-
Data-types | Example |
Numbers- int float | a=1058 x=0.5 |
String- str | nm=”name” |
Boolean- bool | Boolean can only have true or false |
List | c=[1,3,4] |
Tuple | d=(1,2,5,6) |
Print statement:-
Syntax:-
print(variable1,variable2,variable3)
Example:-
a=3
b=5.9
c="python" #its string. Anything within "" is string.
d=[1,2,3]
g,h,k,l=3,4.7,10,"pythonics" #you can do multiple assignments by the method shown
print(" the output is"," a=",a," b=",b)
print(c,d)
print(g," ",h," ",l)
Output:-
![](https://phypythonics.wordpress.com/wp-content/uploads/2021/02/img_20210219_001039.jpg?w=695)
Type conversion:- Data types of the variables can be converted in the following ways:
Syntax:-
v2=datatype(v1)
Example:-
a=2.7
b=int(a) #float to integer
print(" b=",b)
c=3
d=float(c) #integer to float
e=str(a) #float to string
print(" d=",d," e=",e)
Output:-
![](https://phypythonics.wordpress.com/wp-content/uploads/2021/02/img_20210219_105254.jpg?w=650)
Input statement:- This allows user to input while the program is running.
Syntax:-
var=datatype(input(“enter”))
If you don’t specify the data-type, the value which user inputs is stored as a string ,so you can’t perform any arithmetic operation with it.
Example:
a=int(input("enter number "))
print(a)
b=float(input("enter number2 "))
print(b)
Output:
![](https://phypythonics.wordpress.com/wp-content/uploads/2021/02/img_20210219_165008.jpg?w=688)