-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_list.py
More file actions
40 lines (33 loc) · 1.13 KB
/
using_list.py
File metadata and controls
40 lines (33 loc) · 1.13 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
40
shoplist = ["apple", "carrot", "banana", "abc"]
print("item 0 is ", shoplist[0])
print("item 1 is ", shoplist[1])
print("item 2 is ", shoplist[2])
print("item 3 is ", shoplist[3])
print("item -1 is ", shoplist[-1]) #最后一个元素
print("item -2 is ", shoplist[-2]) #倒数第二个
print("item 1 to 3 is", shoplist[1:3]);
print("item 2 to end is", shoplist[2:]);
print("item 1 to -1 is", shoplist[1:-1]);
print("item start to end is", shoplist[:]);
name = "swaroop"
print("characters 1 to 3 is", name[1:3])
print("characters 2 to end is", name[2:])
print("characters 1 to -1 is", name[1:-1])
print("characters start to end is", name[:])
'''
print("i have", len(shoplist), "items to purchase.")
print("This items are:")
for item in shoplist:
print(item)
print ("\nalso have to buy rice.")
shoplist.append("rice2")
print("my shopping list is now", shoplist)
print("i will sort my list now")
shoplist.sort(key=None, reverse=False)
print("my sorted shopping list is now", shoplist)
print("the first item i wil buy is", shoplist[0])
olditem = shoplist[0]
del olditem
print("i bought the", shoplist[0])
print("my shoppint list is now", shoplist)
'''