当前位置:网站首页>第二章 第二十三节:文件操作:读
第二章 第二十三节:文件操作:读
2022-07-21 18:20:00 【中亿丰数字科技有限公司】
Python基础入门(全套保姆级教程)
第二章
第二十三节:文件操作:读
文件操作:
读
strip:去掉字符串左右两端的空白. 空格, 换行, 制表符
read:全部读取
readline:逐行读取
readlines:读出来放入列表
for in :从中读取到每一行数据
f = open("国产自拍.txt", mode="r", encoding="utf-8")
content = f.read() # 全部读取
print(content)
line = f.readline().strip() # 去掉字符串左右两端的空白. 空格, 换行, 制表符
print(line)
line = f.readline().strip()
print(line)
line = f.readline().strip()
print(line)
content = f.readlines() ### 打印出来放入列表
print(content)
print("呵呵哒") # print内部存在一个换行
print("么么哒")
#最重要的一种文本读取方式(必须掌握)
for line in f: # 从f中读取到每一行数据
print(line.strip())
总结:
for xx in xx:重点
边栏推荐
猜你喜欢
随机推荐
24. 合并K个升序链表
Three ways to turn the extra part of the text into an ellipsis
setAttribute、getAttribute、removeAttribute
Introduction to MVC framework
Symbol
微信小程序 不在以下 request 合法域名列表中
Wechat applet is not in the following request legal domain name list
[Datasheet PHY] ksz8081数据手册解读
Responsive layout viewport and common units
25.二叉树的中序遍历
Wechat applet navigation bar sliding transparency change
7年违法处理近650亿条个人信息 滴滴网络安全审查案调查经过公布
获取当前年月和之前的11个月份
数智融合加速驱动企业商业创新
数据访问之JPA
NProgress
Gluttonous snake
加密技术简介
34. 两数相加
小程序输出console