Module 2 Data Types, Operators, Variables Assignment
Module 2 Data Types, Operators, Variables Assignment
data types
please implement it by using python.
1. construct 2 lists containing all the available data types (integer, float, string, complex and
boolean) and do the following..
list1 : [ 1, 0.9, “ string”, 3+4j, “ture”]
list2 : [ 2, 1.5, “ anjana”, 4+5r, “flase”]
a. create another list by concatenating above 2 lists
list3 = list1+list2
print(list3)
o/p = [ 1, 0.9, “ string”, 3+4j, “ture”, 2, 1.5, “ anjana”, 4+5r, “flase”]
2. create 2 sets containing integers (numbers from 1 to 10 in one set and 5 to 15 in other set)
set1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
set2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
print(set1)
print(set2)
a. find the common elements in above 2 sets.
set3 = set1 & set2
print(set3)
o/p = {5,6,7,8,9,10}
b. find the elements that are not common.
set4 = set1 | set 2
print(set4)
o/p = { 1,2,3,4,11,12,13,14,15}
c. remove element 7 from both the sets.
set1.discard[7]
set2.discard[7]
print(set1)
print(set2)
o/p =
{ 1, 2, 3, 4, 5, 6, 8, 9, 10}
3. create a data dictionary of 5 states having state name as key and number of covid-19 cases as
values.
state_covid = {
“andhra” = 1234
“tamil nadu” = 5678
“goa” =2345
“karnataka” = 4567
“kerala ”=6789
}
print(state_covid)
o/p = { “andhra” = 1234, “tamil nadu” = 5678, “goa” =2345, “karnataka” = 4567,
“kerala ”=6789}
state_covid[andhra] = 2345
print(state_covid)
o/p = { “andhra” = 2345, “tamil nadu” = 5678, “goa” =2345, “karnataka” = 4567,
“kerala ”=6789}
operators
please implement by using python
if equation == x:
print('it is a valid relation')
b. “when i divide 5 with 3, i get 1. but when i divide -5 with 3, i get -2”—how would you justify
it?
a=5
b=3
c = -5
print(c//b) #remainder
-2
a/=b
print(a)
0/p = 1.666666666667
c*=5
print(c)
0/p = 50
c = a**b
print(c)
variables
please implement by using python
a. age1=5
print(age1)
o/p = 5
b. 5age=55
print(5age)
o/p = syntax error
a = 124
del a