'''
    作者:Z_Howe01
    版本:4.0
    功能:读取已保存的文件
    日期:2019/1/24
'''

方法一:read

#方法一:read
f = open('password_zh1.txt','r')
u = f.read()
print(u)
f.close()
print()

结果为:

python案例:读取文件方式
方法二:readline

#方法二:readline
s = open('password_zh1.txt','r')
e = s.readline()
print(e)
s.close()

结果为:
python案例:读取文件方式

方法三:readlines

#方法三:readlines
f = open('password_zh1.txt','r')
q = f.readlines()
print(q)
f.close()

结果为:
python案例:读取文件方式

方法四:for循环

#方法四:for循环
f = open('password_zh1.txt','r')
s = f.readlines()
for i in range(len(s)):
    print(s[i])
f.close()

结果为:
python案例:读取文件方式

方法五:for循环

#方法五:for循环
f = open('password_zh1.txt','r')
for i in f.readlines():
    print(i)
f.close()

结果为:
python案例:读取文件方式

方法六:for循环

#方法六:for循环
f = open('password_zh1.txt','r')
for i in f:
    print(i)
f.close()

结果为:
python案例:读取文件方式

附文件:password_zh1.txt
python案例:读取文件方式

相关文章: