1 Answers
📚 Introduction to the `print()` Function
The print() function is a fundamental tool in Python for displaying output to the user. It's like telling the computer to show something on the screen.
🎯 Learning Objectives
- ✏️ Understand the basic syntax of the
print()function. - 💻 Use
print()to display simple text. - 🔢 Use
print()to display numbers. - ➕ Combine text and numbers in a single
print()statement.
📃 Materials
- 💻 A computer with Python installed.
- ⌨️ A text editor or Integrated Development Environment (IDE) like VS Code or Thonny.
🔥 Warm-up (5 mins)
What is Output? Output is information that a computer gives back to us. When you type something and see it on the screen, that's output!
Brainstorm: Think of three things you want your computer to say.
👨🏫 Main Instruction
-
✍️ Basic Syntax
The basic syntax of the
print()function is:print("What you want to say")The text you want to display goes inside the parentheses
()and is enclosed in quotation marks"". -
💬 Displaying Text
To display the text "Hello, world!", you would write:
print("Hello, world!")When you run this code, "Hello, world!" will appear on the screen.
-
🔢 Displaying Numbers
You can also display numbers using the
print()function:print(42)This will display the number 42 on the screen. Notice that numbers don't need quotation marks.
-
➕ Combining Text and Numbers
To combine text and numbers, you can use commas
,inside theprint()function:print("The answer is", 42)This will display "The answer is 42" on the screen.
-
✨ Using Variables
First, create a variable:
my_name = "Your Name"Then, print it!
print("Hello,", my_name)
📝 Assessment
Let's check what you've learned.
- 🖥️ What is the output of
print("Python is fun!")? - 🔢 What is the output of
print(100)? - ➕ What is the output of
print("The number is", 5)? - 💬 Write a line of code that prints your name.
- ➕ Write a line of code that prints "I am" followed by your age.
- ➕ What will
print("1 + 1 =", 1+1)output? - 💡 Explain, in your own words, what the
print()function does.
Join the discussion
Please log in to post your answer.
Log InEarn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀