码迷,mamicode.com
首页 > 其他好文 > 详细

day13(基本语法练习题)

时间:2018-03-14 22:38:29      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:format   语法   ==   strip   with   tar   and   元祖   lex   

 

技术分享图片

#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)

技术分享图片

#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)

技术分享图片

#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对应的值是元祖不能修改

 

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

day13(基本语法练习题)

标签:format   语法   ==   strip   with   tar   and   元祖   lex   

原文地址:https://www.cnblogs.com/mjiu/p/8570540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!