From e24e86fbee3b872a0908e2e4d58bad48c83284ed Mon Sep 17 00:00:00 2001 From: Arisha Date: Tue, 27 Feb 2024 22:12:27 +0530 Subject: [PATCH 1/2] data types in pyhton --- basics/data_types.py | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 basics/data_types.py diff --git a/basics/data_types.py b/basics/data_types.py new file mode 100644 index 0000000..ebc232f --- /dev/null +++ b/basics/data_types.py @@ -0,0 +1,65 @@ +#DATA TYPES IN PYTHON +# Few built-in data types in python are: + +# Numbers +a = 5 +print("The type of a is:",type(a)) #type of variable +b = 40.5 +print("The type of b is:",type(b)) #type of variable +print("b is a floating point number",isinstance(40.5,float)) +c = 1+3j +print("The type of c is:",type(c)) #type of variable +print("c is a complex number",isinstance(1+3j,complex)) + +#string +str1 = "hello python" +str2 = "how are you" +print(str1[0:2]) +print(str1[4]) +print(str1*2) +print(str1 +str2) + +#list +li1 = [1,"hi","python",2] +print(type(li1)) #type of list +print(li1) #print the list +print(li1[3:]) #list slicing +print(li1[0:2]) #list slicing +print(li1 + li1) #list concatination +print(li1*2) #list repetition + +#tuple +tu1 = (20 , "apple","sky",12.4) #define a tuple +print(type(tu1)) #type of tuple +print(tu1) #print the tuple +print(tu1[0:3]) #slicing a tuple +print(tu1[:2]) #slicing a tuple +print(tu1 + tu1) #concatination of tuple +print(tu1 * 3) #repition of tuple +tu1[3] = 30 #adding a new element in a tuple results in error + + +#dictionary +d = {1:'Aakash', 2:'Suman', 3:'Janvi', 4:'Ravi'} #define a dictionary +print(d) #print a dictionary +print("1st name is",d[1]) #accessing a dictionary +print("2nd name is"+d[4]) +print(d.keys()) #accessing keys +print(d.values()) #accessing values + + +#boolean +print(type(True)) #class boolean +print(type(False)) +a = False #define a boolean +print(a is True) #print bool is true + +#set +set1=set() #creating empty set +set2={20, 'python', 82.3, 'Alex'} #creating a set +print(set2) #printing a set +set2.add(30) #adding an element in the set +print(set2) #accesing modified set +set2.remove(30) #removing an element from the set +print(set2) +print(set1) From f702dcbd1b742917c0b95df94fba2d00dd96a1b8 Mon Sep 17 00:00:00 2001 From: Arisha Date: Tue, 27 Feb 2024 22:15:11 +0530 Subject: [PATCH 2/2] data types in python --- basics/data_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/data_types.py b/basics/data_types.py index ebc232f..a731a6e 100644 --- a/basics/data_types.py +++ b/basics/data_types.py @@ -1,5 +1,5 @@ #DATA TYPES IN PYTHON -# Few built-in data types in python are: +# Built-in data types in python are: # Numbers a = 5