字符串,列表,元组
字符串,列表,元组, 练习:
#判断120是否在对象s列表当中 s = ["zhiqiao","lingyan",["yan"],520] i = 120 in s print(i) False #修改列表 s = ["zhiqiao","qiao",["yan"],12] i = s[2] = "ling","yan" #通过索引的方式进行修改和添加第二与第三个元素为ling,yan for i in s: print(i) #删除列表del s = ["zhiqiao","qiao",["yan"],12] del s[1] #删除列表第一个元素"qiao" print(s) ##字符串可以转换为列表,列表可以转换为元组, 反过来也都一样 ##若想修改元组,必须得先装换成元组或者字符串,因为元组当中的元素不可被修改 #将列表转换为元组或字符串 s = ["zhiqiao","qiao",["yan"],12] print(tuple(s),str(s)) #字符串,元组,列表只要不带数字都可以用join连接. 第一个元素被系统占用自动从第二个元素开始 连接 st = "zhi","ling" li = ["zhiqiao","lingyan", "520"] tu = ("qiao","yan",) #建议元组末尾加逗号来表示元组,以免与其他参数弄混淆 v = "_hello_".join(li)+"","".join(tu)+"","".join(st) #可多次使用join结合字符串,与数据库 的join用法一样 print(v)