对于一个空的Python列表,往后添加内容有很多种,其中两种一个是用“+”直接添加内容,另外一种是Listname.append(x)来添加内容 其中,如果处理字符串 在使用“+”的时候,会将字符串拆成一个个列表元素(注:考虑到字符串可以用“[]”操作,所以“当作”列表更贴切),分别添加在列表后面,而用append则是将字符串打包成一个元素,添加到列表中. 例如,如果使用append: all = []print "\nEnter lines('.' by itself to quit).\n&
#使用{}的方法 s1 = 'Hello {}! My name is {}.'.format('World', 'Python猫') print(s1) s2 = 'Hello {0} My name is {1}.'.format('world','Python 猫') print(s2) s3 = 'Hello {name1}! My name is {name2}.'.format(name1='world',name2='Python 猫') print(s3) #使用 % 的方法 p