Python学习笔记——print&列表

xiaoxiao2021-02-27  332

print

message1 = "Hello Word" message2 = "Hello Pytnon Word!,my name is gaishUdong ,welcOme to china" message = message1 + " " + message2 print("Hello"+message+"!") print (message.title())#格式化输出,按照首字母大写形式。 print(message.lower())#格式化输出,全部小写所有字母 print(message.upper())#格式化输出,全部大写所有字母

列表

dizhi = ['安','布达拉','东莞','福建','西藏'] print('I Want go to') print(dizhi) print('I Want goto 顺序排列') print(sorted(dizhi)) print('I Wang Goto ') print(dizhi) print('反序排列') dizhi.reverse() print(dizhi) print("反序排列了反序") dizhi.reverse() print(dizhi) print("永久修改列表的排列顺序") dizhi.sort() print(dizhi) print("永久反序修改列表的排列顺序") dizhi.sort(reverse=True) print(dizhi) len(dizhi) print(len(dizhi)) print(dizhi[3]) L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa'] ] # 打印Apple: print(L[0][0])#多维数组取值 # 打印Python: print(L[1][1]) # 打印Lisa: print(L[2][2]) L.insert(2,'feixiang')#指定位置追加值 L.insert(1,'feixiang')#指定位置添加值 A = len(L)#读取列表长度 print(A) B = L.append('奥迪')#列表末尾追加值 print(L) C = L.insert(1,'大众')#指定位置插入值 print(L) D = L.pop(1)#取出指定位置的值 print(D) L[0] = 'daapple' print(L)
转载请注明原文地址: https://www.6miu.com/read-3637.html

最新回复(0)