//我直接转义 a = r'\(~_~)/ \(~_~)/' b = r'''Python is created by "Guido". It is free and easy to learn. Let's start learn Python in imooc!''' print(a) print(b)
1 2 3 4 5 6 7 8 9 10 11 12
//格式输出 # 指定{}的名字w,c,b,i template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.' world = 'World' china = 'China' beijing = 'Beijing' imooc = 'imooc' # 指定名字对应的模板数据内容 result = template.format(w = world, c = china, b = beijing, i = imooc) print(result) # ==> Hello World, Hello China, Hello Beijing, Hello imooc.
print ("我叫 %s 今年 %d 岁!" % ('小明', 10))# 感觉不如?
1 2 3 4 5
//字符串切片 //s[起点:终点] s = 'ABC' ab = s[0:2] # 取字符串s中的第一个字符到第三个字符,不包括第三个字符 print(ab) # ==> AB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//list L = ['Alice', 66, 'Bob', True, 'False', 100] print(L) for i in L://遍历 print(i) sub_L = L[0:5]//切片,超出去不会报错 print(L[-2])//倒数第二个 L.append('ll')//从末尾添加元素 L.insert(1, 'a')//在L[1]后添加元素 L.pop()//删除最后一个元素,并且返回该元素的值 L.pop(2)//删除L[2] a = L.pop()//可以赋值