Before you get mad at me for asking this question, I have looked for the answer but still can't seem to get what exactly they do. I saw this one answer by a user named "marcog" on SOF. For example :

在你因为提出这个问题而生我的生气之前,我已经找到了答案,但似乎仍无法得到他们到底做了什么。我在SOF上看到了一个名为“marcog”的用户的回答。例如 :

name = "marcog"
number = 42
print "%s %d" (name, number)

What I did then was deleting this part and the code still outputs the exact same thing.

我所做的就是删除这部分,代码仍然输出完全相同的东西。

name = "marcog"
number = 42
print(name, number)

Could you please briefly explain the reason we use them ? By the way, I'm using 3.3.1.

你能简单解释一下我们使用它们的原因吗?顺便说一下,我正在使用3.3.1。

3 个解决方案

#1


12

It tells print to output a string (%s) and a signed integer (%d). This is more useful if you want to have a more complicated output. For example:

它告诉print输出一个字符串(%s)和一个有符号整数(%d)。如果您想要更复杂的输出,这将更有用。例如:

print("Hello %s your number is %d" % (name, number))

With the sample values you've given, this will output:

使用您给出的样本值,这将输出:

Hello marcog your number is 42

你好marcog你的号码是42

更多相关文章

  1. 如何在python中使用命名组和datadict从正则表达式模式中组合字符
  2. 字符串压缩 牛客网 程序员面试金典 C++ Python
  3. Python 用hashlib求中文字符串的MD5值
  4. 将字节列表转换为字节字符串
  5. [D]用python提取多段字符串该怎么写正则表达式。
  6. 如何用位于括号外的逗号分隔字符串?
  7. 用于搜索和替换大字符串的最快Python方法
  8. python 字符串操作
  9. 为什么Python的eval()拒绝这个多行字符串,我如何修复它?

随机推荐

  1. mysql 5.5 zip配置安装
  2. mysql数据库utf-8编码
  3. 机智的MySQL优化器 --- is null
  4. 我需要PHP页面显示mysql数据库中的BLOB图
  5. 利用Intellij+MAVEN搭建Spring+Mybatis+M
  6. MySQL、JDBC安装以及用java连接
  7. mySql中SUBSTRING_INDEX函数用法
  8. mysql数据库之单表查询
  9. MYSQL如何导出存储过程和触发器?
  10. mysql百万级查询怎么样才能快速查询呢