1

I'm practicing for my finals, doing a task where I'm to assign a number to a spot in a row/column system. The suggested method of solving is this:

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))

So I am specifically asking about the content of the print function. Does the {:d} part just mean a dictionary by the name of (row, col, num)?

I was wrong in my assumption that this was about dictionaries. It was actually a formatting tool

I'm sorry if this is a stupid question.

Mats
  • 165
  • 1
  • 3
  • 14

1 Answers1

2

It is a formatting character. It tells the formatter to treat the argument as an integer number and format it as such. Other valid formatters could be x to format it as a hexadecimal number, or b for binary, etc.

See the Format String Syntax, and more specifically, the Format Specification Mini-Language:

'd'
Decimal Integer. Outputs the number in base 10.

Each {...} part is a slot, and the positional arguments to the str.format() method are slotted in in the same order.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343