Bird
Raised Fist0
Pythonprogramming~5 mins

print() function basics in Python - Cheat Sheet & Quick Revision

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the print() function do in Python?
The print() function shows text or other data on the screen so the user can see it.
Click to reveal answer
beginner
How do you print the text Hello, world! using print()?
Use print("Hello, world!") to show the text Hello, world! on the screen.
Click to reveal answer
beginner
Can print() show numbers without quotes? Example: print(123)
Yes, print() can show numbers directly without quotes. It prints the number as is.
Click to reveal answer
beginner
What happens if you use multiple items inside print() separated by commas? Example: print('Age:', 30)
It prints all items separated by spaces. Example output: Age: 30
Click to reveal answer
intermediate
How do you print text on the same line without a new line after using print()?
Use print(..., end='') to stop print() from moving to a new line after printing.
Click to reveal answer
What is the default behavior of print() after printing the content?
AIt moves to a new line
BIt stays on the same line
CIt clears the screen
DIt pauses the program
How do you print multiple items separated by spaces?
AUse plus signs (+) between items
BPut all items inside one string
CSeparate items with commas inside <code>print()</code>
DUse semicolons between items
Which of these will print the number 10?
ANone of the above
Bprint('10')
Cprint(10)
DBoth B and C
How to prevent print() from adding a new line after printing?
AUse <code>skip_line=True</code>
BUse <code>end=''</code> parameter
CUse <code>newline=False</code>
DUse <code>start=''</code> parameter
What will print('Hello', 'World') output?
AHello World
BHelloWorld
CHello, World
DHello World
Explain how the print() function works and how to print multiple items.
Think about how you tell a friend multiple things in one sentence.
You got /3 concepts.
    Describe how to print text without moving to a new line after printing.
    Imagine writing on the same line without pressing Enter.
    You got /3 concepts.

      Practice

      (1/5)
      1. What does the print() function do in Python?
      easy
      A. It displays messages or values on the screen.
      B. It saves data to a file.
      C. It reads input from the user.
      D. It creates a new variable.

      Solution

      1. Step 1: Understand the purpose of print()

        The print() function is used to show messages or values on the screen, making it easy to see output from the program.
      2. Step 2: Compare with other options

        Saving data, reading input, or creating variables are done by other functions, not print().
      3. Final Answer:

        It displays messages or values on the screen. -> Option A
      4. Quick Check:

        print() shows output [OK]
      Hint: Remember: print() means show on screen [OK]
      Common Mistakes:
      • Confusing print() with input()
      • Thinking print() saves data
      • Assuming print() creates variables
      2. Which of the following is the correct way to print the words Hello and World separated by a space?
      easy
      A. print('Hello' 'World')
      B. print('Hello' + 'World')
      C. print('Hello', 'World')
      D. print('Hello'; 'World')

      Solution

      1. Step 1: Understand how print separates items

        Using commas in print() separates items with spaces by default, so print('Hello', 'World') prints "Hello World".
      2. Step 2: Check other options

        print('Hello' 'World') joins strings without space; print('Hello' + 'World') concatenates without space; print('Hello'; 'World') uses invalid syntax.
      3. Final Answer:

        print('Hello', 'World') -> Option C
      4. Quick Check:

        Comma adds space in print() [OK]
      Hint: Use commas to print multiple items with spaces [OK]
      Common Mistakes:
      • Forgetting commas between items
      • Using semicolon inside print()
      • Concatenating without spaces
      3. What will be the output of this code?
      print('A', 'B', 'C', sep='-')
      medium
      A. A B C
      B. A-B-C
      C. ABC
      D. A-B C

      Solution

      1. Step 1: Understand the sep parameter in print()

        The sep parameter changes the separator between printed items. Here, it is set to '-'.
      2. Step 2: Apply sep to the items

        Items 'A', 'B', 'C' will be joined with '-' between them, resulting in 'A-B-C'.
      3. Final Answer:

        A-B-C -> Option B
      4. Quick Check:

        sep='-' joins items with dash [OK]
      Hint: sep changes space to your chosen separator [OK]
      Common Mistakes:
      • Ignoring sep and expecting spaces
      • Confusing sep with end
      • Missing quotes around separator
      4. The code below gives an error. What is the problem?
      print('Hello' end='!')
      medium
      A. Missing comma between arguments
      B. end parameter cannot be used
      C. Quotes are incorrect
      D. print() cannot print strings

      Solution

      1. Step 1: Check syntax of print() arguments

        Arguments in print() must be separated by commas. Here, 'Hello' and end='!' are missing a comma.
      2. Step 2: Understand correct usage

        Correct syntax is print('Hello', end='!') with a comma separating the string and the keyword argument.
      3. Final Answer:

        Missing comma between arguments -> Option A
      4. Quick Check:

        Separate print args with commas [OK]
      Hint: Separate print arguments with commas [OK]
      Common Mistakes:
      • Forgetting commas between arguments
      • Thinking end is not allowed
      • Misplacing quotes
      5. How can you print the numbers 1, 2, and 3 on the same line separated by commas, but end the line with a period instead of a newline?
      hard
      A. print(1, 2, 3, sep=',') print(end='.')
      B. print(1, 2, 3, sep='.', end=',')
      C. print(1, 2, 3, sep=', end='.')
      D. print(1, 2, 3, sep=',', end='.')

      Solution

      1. Step 1: Use sep to set commas between numbers

        Setting sep=',' prints numbers separated by commas: '1,2,3'.
      2. Step 2: Use end to replace newline with a period

        Setting end='.' prints a period instead of moving to a new line.
      3. Step 3: Check argument order

        Argument order does not matter, but both sep and end must be included in the same print call.
      4. Final Answer:

        print(1, 2, 3, sep=',', end='.') -> Option D
      5. Quick Check:

        sep=',' and end='.' print 1,2,3. [OK]
      Hint: Use sep for commas and end for period [OK]
      Common Mistakes:
      • Swapping sep and end values
      • Using two print statements instead of one
      • Forgetting to set end to '.'