Courseiva
Strings →hardMultiple Choice

PCAP Strings Practice Question

A developer writes: print('{:,}'.format(1234567)). What is the output?

⚠ Common exam trap

The PCAP exam often tests whether candidates know that the comma in '{:,}' is a literal thousands separator, not a placeholder for any separator, and that it does not adapt to locale-specific symbols like periods or spaces.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

1,234,567

The correct output is '1,234,567' because the format specifier '{:,}' uses the comma as a thousands separator in Python's string formatting. When applied to the integer 1234567, it inserts commas every three digits from the right, producing the locale-independent grouping.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    1234567

    Why it's wrong here

    This value appears if no format specifier is used—print(1234567) or f"{1234567}"—because Python's default string conversion for integers never inserts grouping separators. Since the question asks for the result of a format operation, producing the raw digits means the format code wasn't applied or wasn't included. Therefore this output does not reflect the described format.

  • ✗

    1.234.567

    Why it's wrong here

    Python's format mini-language supports comma and underscore as grouping separators (e.g., {:,} and {:_}), but not a period. A period as a thousands dot would come from locale-aware formatting or manual replacement, neither of which the comma format performs. Additionally, 1.234.567 uses dots as both the thousands separator and potentially a decimal point, which is ambiguous in Python's numeric parsing. So this output is not what the comma format produces.

  • ✗

    1 234 567

    Why it's wrong here

    The comma in a format specifier like {:,} inserts literal commas between digit groups of three; it does not insert spaces. To get 1 234 567 you would need to replace the commas with spaces afterwards or implement a custom grouping function. Because the format mini-language has no built-in 'space' grouping flag, this output cannot be the direct result of using the comma format.

  • ✓

    1,234,567

    Why this is correct

    Using the format specifier {:,} or the equivalent f-string f"{1234567:,}" applies the comma format, which groups digits by thousands from right to left. The integer 1,234,567 is correctly grouped into the three-digit blocks 1, 234, and 567. Python's format mini-language explicitly adds thousands separators when the comma flag is present, so this is the definitive result of formatting the number as described.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.