Python Programming — Data Types

print('Learning Python Is So Easy')
print("I Love Python")
print("2 + 2")
print('2'+'2')
Learning Python Is So Easy
I Love Python
2 + 2
22
print(100)
print(7 - 2)
print(4 + 11)
print(5 * 10)
print(20 / 10)
100
5
15
50
2
print(3.14)
print(5.5 + 15.5)
print(20.5 - 5.6)
print(20.5 * 5)
print(20.5 / 5)
3.14
21.0
14.9
102.5
4.1
print(1 < 2)
print(2 ==(9 - 7))
print(5 > 20)
True
True
False
myList = [1, 20, 'ab', -32, 789, 9.5]#print all items
print(myList)
#print the first item
print(myList[0])
#print the last item
print(myList[-1])
# print from the index 2-4
print(myList[2:5])
#print from the index 0-3
print(myList[:4])
#add items by inserting a specific index
myList.insert(3,'cd')
print(myList)
#add an item at the end of a list
myList.append('i like python')
print(myList)
#delete items by knowing a specific index
del myList[2:4]
print(myList)
#delete items by knowing specific value data
myList.remove('i like python')
print(myList)
#sort items on list data types
myList.sort()
print(myList)
[1, 20, 'ab', -32, 789, 9.5]
1
9.5
['ab', -32, 789]
[1, 20, 'ab', -32]
[1, 20, 'ab', 'cd', -32, 789, 9.5]
[1, 20, 'ab', 'cd', -32, 789, 9.5, 'i like python']
[1, 20, -32, 789, 9.5, 'i like python']
[1, 20, -32, 789, 9.5]
[-32, 1, 9.5, 20, 789]
myTuple =(5,10,15,5,25,50,35,45,30,20,5,40)
#print all items
print(myTuple)
#print the first item
print(myTuple[0])
#print the last item
print(myTuple[-1])
#print from the index 5-7
print(myTuple[5:8])
#print from the index 2-12
print(myTuple[2:])
#Calculate the number of specific items
print(myTuple.count(5))
#search for index on item
print(myTuple.index(50))
#Count all items on the tuple
print(len(myTuple))
#searching for maximum value
print(max(myTuple))
#searching for a minimum value
print(min(myTuple))
#calculate the sum of all items
print(sum(myTuple))
(5, 10, 15, 5, 25, 50, 35, 45, 30, 20, 5, 40)
5
40
(50, 35, 45)
(15, 5, 25, 50, 35, 45, 30, 20, 5, 40)
3
5
12
50
5
285
#set integer
mySet1 = {1,2,3}
print(mySet1)
#mixed data set
mySet = {5, 5.1,'python', (3,4,6)}
print(mySet)
#if we fill in duplication, the set will remove one
mySet = {10,25,25,25,30,30,30,30}
print(mySet)
#Count all items
print(len(mySet))
#searching for maximum value
print(max(mySet))
#searching for a minimum value
print(min(mySet))
#calculate the sum of all items
print(sum(mySet))
#combine the values of two data set types
print(mySet.union(mySet1))
#delete all items
print((mySet.clear))
{1, 2, 3}
{(3, 4, 6), 5.1, 'python', 5}
{25, 10, 30}
3
30
10
65{1, 2, 3, 25, 10, 30}
{}
a = {1:'one', 2:'two', 'three':3, 'name':'Nabil Makarim'} print(a[1]) 
print(a['three'])
print(a['name'])
one
3
Nabil Makarim

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store