{:d} 是什么意思?字符串 Python 3.4.3
What does {:d} mean? Strings Python 3.4.3
我正在为我的期末考试练习,做一个任务,我要在 row/column 系统中为一个点分配一个数字。建议的解决方法是:
def readOneNumber():
row = int(input("Row (1-9): "))
col = int(input("Column (1-9): "))
num = int(input("The number (1-9): "))
print("Position ({:d},{:d}) now contains {:d}".format(row, col, num))
所以特意问一下打印功能的内容。 {:d} 部分是否仅表示名称为 (row, col, num) 的字典?
我错误地认为这是关于字典的。它实际上是一个格式化工具
如果这是一个愚蠢的问题,我很抱歉。
这是一个格式化字符。它告诉格式化程序将参数视为整数并将其格式化。其他有效的格式化程序可以是 x
将其格式化为十六进制数,或 b
用于二进制等。
参见Format String Syntax, and more specifically, the Format Specification Mini-Language:
'd'
Decimal Integer. Outputs the number in base 10.
每个 {...}
部分都是一个插槽,str.format()
method 的位置参数以相同的顺序插入。
我正在为我的期末考试练习,做一个任务,我要在 row/column 系统中为一个点分配一个数字。建议的解决方法是:
def readOneNumber():
row = int(input("Row (1-9): "))
col = int(input("Column (1-9): "))
num = int(input("The number (1-9): "))
print("Position ({:d},{:d}) now contains {:d}".format(row, col, num))
所以特意问一下打印功能的内容。 {:d} 部分是否仅表示名称为 (row, col, num) 的字典?
我错误地认为这是关于字典的。它实际上是一个格式化工具
如果这是一个愚蠢的问题,我很抱歉。
这是一个格式化字符。它告诉格式化程序将参数视为整数并将其格式化。其他有效的格式化程序可以是 x
将其格式化为十六进制数,或 b
用于二进制等。
参见Format String Syntax, and more specifically, the Format Specification Mini-Language:
'd'
Decimal Integer. Outputs the number in base 10.
每个 {...}
部分都是一个插槽,str.format()
method 的位置参数以相同的顺序插入。