0
0
Pythonprogramming~10 mins

print() function basics in Python - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - print() function basics
Start
Call print()
Evaluate arguments
Convert to string
Send to output (screen)
End
The print() function takes inputs, converts them to text, and shows them on the screen.
Execution Sample
Python
print("Hello, world!")
This code prints the text Hello, world! on the screen.
Execution Table
StepActionInputOutput
1Call print()"Hello, world!"Prepare to print
2Evaluate argument"Hello, world!""Hello, world!" as string
3Send to output"Hello, world!"Hello, world! displayed on screen
4End--
💡 print() finishes after showing the text on the screen
Variable Tracker
VariableStartAfter print() callFinal
argumentNoneNoneNone (print does not store)
Key Moments - 2 Insights
Why does print() show text but not store it in a variable?
print() only sends text to the screen; it does not save or return any value. See execution_table step 3 where output is displayed but no variable changes.
What happens if we print a number instead of text?
The number is converted to text before printing, just like the string. This is shown in execution_table step 2 where input is converted to string.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output at step 3?
AThe text is displayed on the screen
BThe text is stored in a variable
CThe program stops running
DNothing happens
💡 Hint
Check the Output column at step 3 in the execution_table
According to the variable tracker, what happens to the argument variable after print() is called?
AIt keeps the printed text
BIt becomes None
CIt is deleted
DIt changes to a number
💡 Hint
Look at the 'After print() call' column for 'argument' in variable_tracker
If we change print("Hello") to print(123), what changes in the execution flow?
AThe output will be a number type on screen
Bprint() will not work with numbers
CThe argument is converted to string before printing
DThe program will crash
💡 Hint
Refer to concept_flow and execution_table step 2 about argument evaluation
Concept Snapshot
print() function basics:
- Use print() to show text or values on screen
- Arguments are converted to strings automatically
- print() does not save or return values
- Syntax: print(value1, value2, ...)
- Each call outputs on a new line by default
Full Transcript
The print() function in Python is used to show messages or values on the screen. When you call print(), it takes the input you give it, changes it into text if needed, and then shows it on the screen. It does not save the text anywhere or return any value. For example, print("Hello, world!") will display Hello, world! on the screen. The process starts by calling print(), then the input is evaluated and converted to a string, and finally the text is sent to the output. After printing, the program continues or ends. Variables passed to print() do not change or store the printed text. This is important to understand so you know print() is only for showing information, not for storing it.