forked from navinreddy20/Python-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6 List in Python
68 lines (66 loc) · 1.4 KB
/
6 List in Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Code
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> nums = [25,12,36,95,14]
>>> nums
[25, 12, 36, 95, 14]
>>> nums[0]
25
>>> nums[54\]
SyntaxError: unexpected character after line continuation character
>>> nums[54]
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
nums[54]
IndexError: list index out of range
>>> nums[4]
14
>>> nums[2:]
[36, 95, 14]
>>> nums[-1]
14
>>> nums[-5]
25
>>> names = ['navin','kiran','john']
>>> names
['navin', 'kiran', 'john']
>>> values = [9.5,'Navin',25]
>>> mil = [nums, names]
>>> mil
[[25, 12, 36, 95, 14], ['navin', 'kiran', 'john']]
>>> nums.append(45)
>>> nums
[25, 12, 36, 95, 14, 45]
>>> nums.insert(2,77)
>>> nums
[25, 12, 77, 36, 95, 14, 45]
>>> nums.remove(14)
>>> nums
[25, 12, 77, 36, 95, 45]
>>> nums.pop(1)
12
>>> nums
[25, 77, 36, 95, 45]
>>> nums.pop()
45
>>> del nums[2:]
>>> nums
[25, 77]
>>> nums.extend(29,12,14,36)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
nums.extend(29,12,14,36)
TypeError: extend() takes exactly one argument (4 given)
>>> nums.extend([29,12,14,36])
>>> nums
[25, 77, 29, 12, 14, 36]
>>> min(nums)
12
>>> max(nums)
77
>>> sum(nums)
193
>>> nums.sort()
>>> nums
[12, 14, 25, 29, 36, 77]
>>>