day13(基本语法练习题)

时间:2023-02-22 14:39:47

 

day13(基本语法练习题)

#1
li = ['jiu','lin','liang']
print ("{0}{1}{2}{3}{4}".format(li[0],'_',li[1],'_',li[2]))
#2
li = ["alec", " aric", "Alex", "Tony", "rain"]
for l in li :
if l.strip().startswith("a") == True or l.strip().startswith("A") and l.strip().endswith("c"):
print(l.strip())

tu
= ("alec", " aric", "Alex", "Tony", "rain")
for l in tu :
if l.strip().startswith("a") == True or l.strip().startswith("A") and l.strip().endswith("c"):
print(l.strip())

dic
= {'k1': "alex", 'k2': ' aric', "k3": "Alex", "k4": "Tony"}
for l in dic.values() :
if l.strip().startswith("a") == True or l.strip().startswith("A") and l.strip().endswith("c"):
print(l.strip())

#3

#3
li = ['alex','eric','rain']
print(len(li))
li.append(
"seven")
print(li)
li.insert(0,
"Tony")
print(li)
li[
1] = "Kelly"
print(li)
li.pop(li.index(
"eric"))
print(li)
li_2
= li[1]
li.pop(
1)
print(li_2,li)
print(li)
li.pop(
3)
print(li[3:])
li.pop(
2,4)
print(li)
print(li[::-1])for k in range(len(li)):
print(k)
for k,y in enumerate(li):
print(k+100,y)

day13(基本语法练习题)

#4
li = ["hello", 'seven', ["mon", ["h", "kelly"], 'all'], 123, 446]
print(li[2][1][1])
li[
2][2] = 'ALL'
print(li)

#5

#5
tu = ('alex', 'eric', 'rain')
print(len(tu))
print(tu[2])
print(tu[1],tu[2])
for i in tu:
print(i)
for i in range(len(tu)):
print(i)
for k,y in enumerate(tu):
print(k+10,y)

day13(基本语法练习题)

#6
tu = ("alex", [11, 22, {"k1": 'v1', "k2": ["age", "name"], "k3": (11,22,33)}, 44])
#1,只读列表,2,不能修改
#
不可以
#
k2是 字典,对应的值是列表可以被修改
tu[1][2]["k2"].append("Seven")
print(tu)
#k3对应的值是元祖不能修改

 

未完待遇~~~~~~~~~