🖨️
Output with print()
Show results in the console
Reward
+40 XP
The print function
print() writes text to the output. You can pass several values separated by commas.
print("Hello, world!")
print("x =", 42)sep and end
Use sep to change the separator between values and end to change what appears at the end (default newline).
print("a", "b", "c", sep="-")
print("no newline", end="")
print(" same line")f-strings
f-strings let you embed expressions inside curly braces for cleaner formatting.
name = "Ada"
age = 36
print(f"{name} is {age} years old")Try it yourself
Run the example below. Edit it and see what changes.
main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)
Common mistakes
- ⚠Forgetting parentheses: print "hi" is invalid in Python 3.
- ⚠Concatenating numbers with strings using +. Use a comma or f-string.
- ⚠Forgetting the f before the string in f-strings.
