python学习第三章-一些补充

本文介绍了Python中的print函数,包括其参数和用途,详细讲解了str()和repr()的区别,并探讨了文件的打开方式,特别是使用pickle模块实现对象的保存和提取。还讨论了open()函数的参数和使用场景。
摘要由CSDN通过智能技术生成

print()函数用法

print(…)
print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

flush:将缓存里面的内容立即输出到标准输出流(这里是sys.stdout, 也就是默认的显示器),true为立即返回。
若写入文件,flush为false时,f.close()执行前文件无内容,flush为True,则f.close()执行前有内容。

str()和repr()的区别

str():返回用户易读的表达形式
repr():返回解释器易读的表达形式

class str(object)
| str(object=’’) -> str
| str(bytes_or_buffer[, encoding[, errors]]) -> str

repr(obj, /)
Return the canonical string representation of the

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值