-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-lists.py
More file actions
47 lines (32 loc) · 721 Bytes
/
3-lists.py
File metadata and controls
47 lines (32 loc) · 721 Bytes
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
# A List is a collection which is ordered and changeable. Allows duplicate members.
numbers = [ 3, 23, 111, 3423, 352]
print(numbers)
print(type(numbers))
#using a constructor
listNum = list (( 213, 11, 342, 2342, 55432))
print(listNum)
fruits = ['Apples', 'Oranges', 'Grapes', 'Pears']
print(fruits[2])
#Get len
print(len(fruits))
#append to the list
fruits.append('Mango')
print(fruits)
#remove from the list
fruits.remove('Grapes')
print(fruits)
#insert into a spot
fruits.insert(2, 'Coconut')
print(fruits)
#remove from a spot
fruits.pop(4)
print(fruits)
#reverse list
fruits.reverse()
print(fruits)
#sort an array
fruits.sort()
print(fruits)
#reverse the sort
fruits.sort(reverse=True)
print(fruits)