python之零碎知识
一 join方法 主要是做字符串的拼接:join后面跟的类型必须是要可迭代得到对象 for循环的对象是可迭代对象 # result = "".join(li) # print(result) msg = "" is_first = True for item in li: if is_first: tmp = item is_first =False else: tmp = "_" + item # _alex msg += tmp print(msg) 二 break 和 contionue在for循环中也可以使用,用法和while循环一样 break还可以退出当前的循环,回到上一级的循环 1 for i in range(1,10): 2 print(i) 3 for i in range(10,20): 4 print(i) 5 6 for i in range(1,10): 7 print(i) 8 break 9 for i in range(10,20): 10 print(i) 11 for i in range(1,10): 12 print(i) 13 for i in range(10,20): 14 print(i) 15 break 16 17 for i in range(1,10): 18 print(i) 19 for i in range