简体   繁体   English

任何人都可以帮助我了解这部分 python 代码是什么意思吗?

[英]Can anyone help me with what does this part of python code mean?

我想知道这一小部分代码是什么意思,因为在脚本创建的文件中,它似乎在最后添加了一行,我相信它可能是这些符号之一

opened_file.write("%s\n" %user_input)

It writes a line.它写了一行。 The content of user_input replaces the %s (see string interpolation in the docs) and \\n is the newline character - after user_input . user_input的内容替换了%s (参见文档中的字符串插值), \\n是换行符 -user_input之后

Here is a good description of the different "inserting data into strings" methods, including % interpolation (which is now considered outdated):这是对不同的“将数据插入字符串”方法的一个很好的描述,包括 % 插值(现在被认为是过时的):

https://realpython.com/python-string-formatting/ https://realpython.com/python-string-formatting/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM