In [3]: list1 = [10,20,30,40,50]
In [4]: list1[2]
Out[4]: 30
In [6]: list1[4]
Out[6]: 50
In [8]: list1[-2]
Out[8]: 40
In [9]: list1[:1]
Out[9]: [10]
In [11]: list1[:2]
Out[11]: [10, 20]
In [12]: list1[:3]
Out[12]: [10, 20, 30]
In [13]: list1[0:1]
Out[13]: [10]
In [14]: list1[1:3]
Out[14]: [20, 30]
In [15]: list1
Out[15]: [10, 20, 30, 40, 50]
In [17]: list1[1:5]
Out[17]: [20, 30, 40, 50]
In [18]: list1[:]
Out[18]: [10, 20, 30, 40, 50]
In [19]: list1[1:]
Out[19]: [20, 30, 40, 50]
In [20]: list1[:1]
Out[20]: [10]
In [21]: list1[:2]
Out[21]: [10, 20]
In [22]: list1[2:]
Out[22]: [30, 40, 50]
In [23]: list1[:-1]
Out[23]: [10, 20, 30, 40]
In [24]: list1 = [1,2,3]
list2 = [4,5,6]
combine = list1+list2
In [25]: print(combine)
[1, 2, 3, 4, 5, 6]
In [26]: print(type(combine))
<class 'list'>
In [27]: list1
Out[27]: [1, 2, 3]
In [30]: new_list = list1 *4
In [31]: new_list
Out[31]: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
In [32]: list1 = [10,20,30,40,50]
In [33]: list1
Out[33]: [10, 20, 30, 40, 50]
In [34]: result = 20 in list1
In [35]: print(result)
True
In [36]: result = 80 in list1
In [37]: print(result)
False
In [38]: list1 = [1,2,3]
list2 = [1,2,3]
print(list1 is list2)
False
In [39]: list1 = [1,2,3]
list2 = [1,2,3]
print(list1 == list2)
True
In [40]: list3 = list1
In [42]: print(list1 is list3)
True
In [43]: my_list = list1
In [44]: print(list1 is my_list)
True
In [45]: list1 = [10,20,30,40,50]
In [46]: print(len(list1))
In [47]: list1
Out[47]: [10, 20, 30, 40, 50]
In [48]: for i in list1:
print(i)
10
20
30
40
50
In [53]: square = [x**2 for x in range(5)]
In [54]: square
Out[54]: [0, 1, 4, 9, 16]
In [56]: for x in range(5):
square = x**2
print(square)
0
1
4
9
16
In [59]: fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
newlist = []
for x in fruits:
if "a" in x:
[Link](x)
In [60]: newlist
Out[60]: ['apple', 'banana', 'mango']
In [61]: newlist = [x for x in fruits if "a" in x]
In [62]: newlist
Out[62]: ['apple', 'banana', 'mango']
In [63]: list1
Out[63]: [10, 20, 30, 40, 50]
In [64]: [Link](60)
In [65]: list1
Out[65]: [10, 20, 30, 40, 50, 60]
In [66]: [Link]([70,80])
In [67]: list1
Out[67]: [10, 20, 30, 40, 50, 60, 70, 80]
In [68]: list2
Out[68]: [1, 2, 3]
In [69]: [Link](list2)
In [70]: list1
Out[70]: [10, 20, 30, 40, 50, 60, 70, 80, 1, 2, 3]
In [71]: list1
Out[71]: [10, 20, 30, 40, 50, 60, 70, 80, 1, 2, 3]
In [72]: list1 = [1,2,3,4]
In [73]: list1
Out[73]: [1, 2, 3, 4]
In [74]: [Link](2,300)
In [75]: list1
Out[75]: [1, 2, 300, 3, 4]
In [76]: list1
Out[76]: [1, 2, 300, 3, 4]
In [77]: [Link](300)
In [79]: list1
Out[79]: [1, 2, 3, 4]
In [80]: [Link](1)
Out[80]: 2
In [81]: list1
Out[81]: [1, 3, 4]
In [82]: [Link]()
Out[82]: 4
In [83]: list1
Out[83]: [1, 3]
In [84]: list1
Out[84]: [1, 3]
In [85]: [Link]()
In [86]: list1
Out[86]: []
In [87]: list2
Out[87]: [1, 2, 3]
In [88]: list3 = list2*3
In [89]: list3
Out[89]: [1, 2, 3, 1, 2, 3, 1, 2, 3]
In [90]: [Link]()
In [91]: list3
Out[91]: []
In [93]: list1 = [1,2,3,2,4,5,2]
[Link](2)
Out[93]: 3
In [94]: list_new = ['yes','np','yes','no','no']
In [95]: list_new
Out[95]: ['yes', 'np', 'yes', 'no', 'no']
In [96]: list_new.count('no')
Out[96]: 2
In [99]: list4 = [50,20,10,60,90,1,100]
[Link]()
print(list4)
[1, 10, 20, 50, 60, 90, 100]
In [98]: list4
Out[98]: [1, 10, 20, 50, 60, 90, 100]
In [100… list4
Out[100]: [1, 10, 20, 50, 60, 90, 100]
In [101… [Link]()
In [102… list4
Out[102]: [100, 90, 60, 50, 20, 10, 1]
In [103… list1= [1,2,3,4,5,6]
list2 = [Link]()
In [104… list2
Out[104]: [1, 2, 3, 4, 5, 6]
In [105… list1 =[10,20,30,40,50,90]
max_no = list1[0]
for i in list1:
if i > max_no:
max_no = i
print(max_no)
90
In [106… list5 = []
print("Enter elements to add to the list. Type 'exit' to stop.")
while True:
user_input = input("Enter the element to add to list or enter 'exit' to finish")
if user_input.lower()=='exit':
break
[Link](user_input)
print("Final List : ",list5)
Enter elements to add to the list. Type 'exit' to stop.
Enter the element to add to list or enter 'exit' to finish10
Enter the element to add to list or enter 'exit' to finish
Enter the element to add to list or enter 'exit' to finish20
Enter the element to add to list or enter 'exit' to finish30
Enter the element to add to list or enter 'exit' to finish40
Enter the element to add to list or enter 'exit' to finish50
Enter the element to add to list or enter 'exit' to finish100
Enter the element to add to list or enter 'exit' to finishexit
Final List : ['10', '', '20', '30', '40', '50', '100']
In [107… my_set={1,2,3,4,5}
In [108… my_set
Out[108]: {1, 2, 3, 4, 5}
In [109… my_set2 =set([10,20,30,40,50])
In [110… my_set2
Out[110]: {10, 20, 30, 40, 50}
In [119… print(type(my_set2))
<class 'set'>
In [117… set1={1,2,3}
set2={3,4,5}
result = set1|set2
In [114… result
Out[114]: {1, 2, 3, 4, 5}
In [120… result = set1&set2
result
In [121… result
Out[121]: {3}
In [122… set1={10,20,30,50,80,}
set2={100,40,30,20,80,}
result = set1&set2
In [123… result
Out[123]: {20, 30, 80}
In [124… set1 = {1,2,3}
set2 = {3,4,5}
result = set1-set2
In [125… result
Out[125]: {1, 2}
In [126… result2 = set2 - set1
In [127… result2
Out[127]: {4, 5}
In [128… set1
Out[128]: {1, 2, 3}
In [129… set2
Out[129]: {3, 4, 5}
In [130… result = set1 ^ set2
In [131… result
Out[131]: {1, 2, 4, 5}
In [147… set1 = {1,2,3,4,5,6,7,8,9}
set2 = {2,4,6,8}
result = set1 >=set2
In [148… result
Out[148]: True
In [1]: set1 = {}
In [2]: import keyword
print([Link])
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'exc
ept', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while',
'with', 'yield']
In [ ]: