Variables, Datatypes and Typecasting
Variables, Datatypes and Typecasting
Variable
# Variable in Python:
abc = "It's a string variable"
_abcnum = 40 # It is an example of int variable
abc123 = 55.854 # It is an example of float variable
print(_abcnum + abc123) # This will give sum of 40 + 55.854
type() Function in Python: type() function is a function
that allows a user to find data type of any variable. It
returns the data type of any data contained in the variable
passed to it.
Have a look at the code below which depicts the use of
type function:
Typecasting :
# Typecasting in Python :
abc = 5
abc2 = '45'
abc3 = 55.95
xyz = 5.0
abc4=int(abc2)
print(abc+abc4) # Output : 50
print(abc+int(abc2)) # Output : 50
Solution :
# Quiz :
print("Enter First Number : ")
num1= input()
print("Enter Second Number : ")
num2=input()
print("The Sum is",num2) #It will give output as sum of two numbers.
var1 = "54"
var4 = "32"
var2 = 4
var3 = 36.7
# print(100 * str(int(var1) + int(var4)) )
# print(100 * "Hello world\n")
# print("Enter your number")
# inpnum = input()
#
# print("You entered", int(inpnum)+10)
"""
str()
int()
float()
"""
"""
Quiz - Solved in the video
Exercise - Next video
Project - Some awesome python utility
"""
# print(type(var1))