Each variable type has its own characteristics and use cases. For example, integers and floats are used for numeric operations, strings are used for text manipulation, Booleans are used for logical operations, lists and tuples are used for storing collections of data, dictionaries are used for storing key-value pairs, and sets are used for storing unique elements.
Each Variable Code With Both Input & Output Shown Below :
- Integer: (Input Is Shown Below)
#Lets print the integer using int
#Code by IAH (Infinity Aggarwal Harshul)
x = 1 #Lets take nay integer value
print(x) #print the integer value
#The output will show print results with integer values
(Output is Shown Below)
2. Float : (Input Is Shown Below)
Code :
#Lets print the float value using float
#Code by IAH (Infinity Aggarwal Harshul)
x = 1.6 #Lets take any float value
print(x) #print the float value
#The output will show print results with float values
(Output is Shown Below)
Code :
#Lets print the string using str
#Code by IAH (Infinity Aggarwal Harshul)
str = input ("Enter Name :") #lets take any string
print(str) #print the string
print(type(str)) #print the type of the string
#The output will show print results with strings
(Output is Shown Below)
Code :
#Lets print the age of the person using the boolean if/else statement
#Code by IAH (Infinity Aggarwal Harshul)
Age = int(input("Enter Age : ")) #Lets take the age of the person using user input value
if (Age >= 18): #if the person is equal to 18 then
print("Age = Valid") #print age of the person is valid
else : #else if the person age is not equal to 18 then
print("Age = Not Valid") #print age of the person is not valid
#The output will show the age of the person is valid or not using user input value
(Output is Shown Below)
Code :
#Entering the numbers in the list and printing them out as a list
#Code by IAH (Infinity Aggarwal Harshul)
list =[ 1,2,3,4,5] #taking a list of some numbers
print(list) #print them in the list
#The output will show the numbers in the list
(Output is Shown Below)
Code :
#Entering the coordinates in the tuple and printing them out as a tuple
#Code by IAH (Infinity Aggarwal Harshul)
coordinates =(10,20) #taking some random coordinates
print(coordinates) #print them in the tuple
print(type(coordinates))
#The output will show the numbers in the tuple
(Output is Shown Below)
#Testing User Input And Storing them in the dictionary and updating them with the new user input data
#Code by IAH (Infinity Aggarwal Harshul)
Name = input("Enter Name: ") #Enter Name using the input string
Age = int(input("Age: ")) #Enter age of the user using the int input string
Gender = input("Gender: ") #Enter gender of the user using the input string
dict = { #This dictionary contains the user input data
"Name" : "a",
"Age" : "b",
"Gender" : "c"
}
dict.update({"Name" : Name}) #now let we upadte the dictionary with the new user data
dict.update({"Age" : Age})
dict.update({"Gender" : Gender})
print(dict) #print the dictionary with the updated user input data
#The output dictionary which contains the user input data will show upadted user input data
(Output is Shown Below)
Code :
#Lets print some numbers in the set
#Code by IAH (Infinity Aggarwal Harshul)
unique_numbers = {1,2,3,4,5} #consider a unique number set
print(unique_numbers) #print unique_numbers
print(type(unique_numbers)) #print the type of unique_numbers
#The output will show the unique numbers in the set and will print its type
(Output is Shown Below)
These examples demonstrate how to create variables of different types in Python. Each variable type serves a specific purpose and has its own set of operations and methods that can be applied to it.

















Comments
Post a Comment