-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSession F3 - lists.py
48 lines (31 loc) · 1.01 KB
/
Session F3 - lists.py
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
myList = [] # this is an empty list
list1 = [1,2,3,0,"Julius",True]
myFruit = ["Apple", "Orange", "Grapes", "Mango", "Pineapple", "Banana"]
print(myFruit[:3])
myBasket = ["Apple", "Orange", "Grapes", "Mango", "Pineapple", "Banana"]
print(myBasket)
subFruit = myBasket[3:6] # creates a new list from an original
print(subFruit)
print(len(myBasket)) # prints how many items are in the list
myBasket.append("Guava") # adds a new item to a list
print(myBasket) # outputs the appended list
myBasket.append("Sugarcane")
myBasket.append("Watermelon")
print(myBasket)
myBasket.extend(["Cherries", "Kiwi", "Lemon", "Peach"])
print(myBasket)
myBasket.pop(0)
print(myBasket)
myBasket.remove("Sugarcane")
print(myBasket)
print(myFruit)
myFruit[5] = "Guava" # replace a specific item
print(myFruit)
myFruit.sort()
print(myFruit)
myFruit.sort(reverse = True)
print(myFruit)
NewFruitBasket = myFruit.copy()
NewFruitBasket.append("Strawberry")
print(NewFruitBasket)
print(myFruit)