博客编码:180915
>>> "{0} is {1}.{2}".format("This", "python", "org") #将括号内部的字符进行替换,其中0,1,2表示的是位置参数 ‘This is python.org‘
>>> "{a} is {b}.{c}".format(a="This", b="python", c="code") #‘a‘,‘b‘,‘c‘表示的是关键字参数,这两种参数可以混合使用,但是位置参数必须在前面
‘This is python.code‘
>>> list = [1, 2, 4, 3, 7, 5] >>> for each in reversed(list): print(each, end = ‘,‘) 5,7,3,4,2,1,
>>> str = "Learn" >>> for each in enumerate(str): print(each) (0, ‘L‘) (1, ‘e‘) (2, ‘a‘) (3, ‘r‘) (4, ‘n‘)
>>> list = [1, 3, 5, 7, 9] >>> str = "Learn" >>> tuple = (2, 4, 6, 8, 10) >>> for each in zip(list, str, tuple): print(each) (1, ‘L‘, 2) (3, ‘e‘, 4) (5, ‘a‘, 6) (7, ‘r‘, 8) (9, ‘n‘, 10)
原文:https://www.cnblogs.com/zwpan/p/9649861.html