-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListvalues.py
More file actions
40 lines (31 loc) · 1.05 KB
/
Copy pathListvalues.py
File metadata and controls
40 lines (31 loc) · 1.05 KB
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
#Defined a system that shows the capabilities of the methods of the list
#Define the list of names
lstname = ["John","Sammy","Sarah","Linda"]
#Python is case sensitive, print the list of names
print(lstname)
#Different ways of adding a new user into the list at a specific position
#place Sammie at index 1 this replaces the individual at index 1
lstname[1] = "Sammie"
print(lstname)
#Place sharon at index 1 this doesn't replace the individual at index 1
lstname.insert(1,"Sharon")
print(lstname)
#print all the names in the list
icount = 0
while icount < len(lstname):
print(lstname[icount])
icount += 1
#Add in a new name to the end of the list
lstname.append("Miller")
#Print the list of names to show that the new name is added
print(lstname)
#Remove the name Sharon in the list
lstname.remove("Sharon")
print(lstname)
#Lets check if any name is in our list
searchname = input("Search for: ")
if searchname in lstname:
print(str(lstname.find(searchname)))
else:
print(searchname + ", does not")
print("length of list Items:" + str(len(lstname)))