python - Python如何将打印语句存储在变量中?
问题描述
我喜欢将两个打印语句保存在 2 个不同的变量中。我怎样才能做到这一点?
with open(file_to_open) as f:
for line in f:
# split the line
line = line.strip()
columns = line.split(",")
if columns[0] == "1":
print(line, end='')
if columns[0] == "2":
print(line, end='')
解决方案
print(x)
函数隐含
- 来电
str(x)
- 显示它
- 返回
None
所以,你不能做
stored = print(x)
相反,写
stored_value = str(x)
推荐阅读
- sparql - Marklogic Datahub:三元组的生成
- terraform - Terraform - 带有事件中心端点的 Azure 事件网格订阅
- excel - 数据透视表 - 作为另一个百分比的列
- tensorflow - Tensorflow 官方教程中给出的 Bahdanau's Attention 的两种不同代码有什么区别?
- flutter - 将小部件添加到颤振应用程序会导致 .yaml 文件中的冲突
- vba - 根据其他记录的值添加记录
- javascript - 当我尝试使用雪花存储过程执行更改命令时给出错误?
- python - 将一行分解为多行
- r - 在 R 中清理脏名称数据
- networking - 当 .1 不是 TLD 时,1.1.1.1 如何解析为网站