-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists.py
30 lines (27 loc) · 1.03 KB
/
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
# Creating a list
simple_list = ["apple", "banana", "cherry"]
print("Simple List")
print(simple_list) # Returns ['apple', 'banana', 'cherry']
print("-----------------------------------")
print("After changing item 3")
simple_list[2] = "blackcurrant"
print(simple_list) # Returns ['apple', 'banana', 'blackcurrant']
print("-----------------------------------")
# The list() Constructor
print("Using the list() constructor")
# note the double round-brackets
this_list = list(("apple", "banana", "cherry"))
print(this_list) # Returns ['apple', 'banana', 'cherry']
print("Length of the list")
print(len(this_list)) # Returns 3
print("-----------------------------------")
# Appending an item
this_list.append("pineapple")
print("After appending an item")
print(this_list) # Returns ['apple', 'banana', 'cherry', 'pineapple']
print("-----------------------------------")
# Removing an item
this_list.remove("apple")
print("After removing an item")
print(this_list) # Returns ['banana', 'cherry', 'pineapple']
print("-----------------------------------")