PYTHON 学习笔记 0011 (休假也要认真学习!!!!!)

二维列表

#二维列表、巢状迴圈#[[],[]]#取值[行],[列]nums = [    [1,2,3,4],    [5,6,7],    [8,9]]print(nums[1][1])

http://img2.58codes.com/2024/20156136DzZTKlVepX.jpg

巢状迴圈

nums = [    [1,2,3,4],    [5,6,7],    [8,9]]#将nums四行的数列放入ROW这个变数中,进入第二层迴圈,再把各行的值放入COL这个变数中,把行放入列中取值,再针对个别动作(印出)。for row in nums:    for col in row:        print(col)

http://img2.58codes.com/2024/20156136DRhc6yPYhk.jpg

档案的读取、写入

#档案的读取、写入open("档案读取",mode="开启模式")#绝对路径 EX: D:/python training/PIC/python001.png#相对路径 以程式的位子做延伸# mode="r" 读取# mode="w" 覆写# mode="a" 在原先的资料后写东西

绝对路径

斜线\需改"/"

>>D:/python training/PIC/python001.png

http://img2.58codes.com/2024/20156136yutJEGeTlQ.jpg

#读取档案file = open("5566.txt", mode="r")print(file.read())file.close()#关闭档案file = open("5566.txt", mode="r")#读取每行资料print(file.readline())file.close()file = open("5566.txt", mode="r")#读取一行接一行print(file.readline())print(file.readline())file.close()file = open("5566.txt", mode="r")#读取全部资料for line in file:    print(line)file.close()file = open("5566.txt", mode="r")print(file.readlines())file.close()

http://img2.58codes.com/2024/20156136UH3Vz81Khe.jpg

http://img2.58codes.com/2024/20156136wQ1Cw9Rsrw.jpg

http://img2.58codes.com/2024/20156136drXaH234Wl.jpg

http://img2.58codes.com/2024/20156136uPp9kEEmaS.jpg

#複写file = open("5566.txt", mode="w")file.write("hi")file.close()

http://img2.58codes.com/2024/20156136adMkaIxuc6.jpg

#维持原模式+複写file = open("5566.txt", mode="a")file.write(" Magic!!!")file.close()

http://img2.58codes.com/2024/20156136XAtHuEuDAi.jpg


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章