Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today we will learn about the print() function. This function is how we will display text on the screen. Can anyone tell me what the first line of code we'll write will look like?
Is it print('Hello, World!')?
Absolutely! That's correct! The print function allows us to output messages. It's important to note that the text inside the parentheses must be enclosed in quotes. Can anyone tell me why we need quotes?
Because it shows Python that it's a string of text?
Exactly! Strings are sequences of characters, and the quotes indicate this. Let’s remember: Quotes equal Strings! Now, who can summarize what we’ve learned?
We learned how to use the print function to display text and that we need quotes for strings!
Next, let's write our first program! Open your code editor, and type in print('Hello, World!'). After that, how do you think we run our program?
We usually hit a run button or type something in the terminal?
Correct! In IDLE, you can press F5, or in VS Code, you can use the built-in terminal to run your code. What happens when we execute this line of code?
It displays 'Hello, World!' on the screen!
Yes, it does! It's our first glimpse into Python programming. Let's summarize: To run a program, we write our code and use the correct functionality to execute it.
Now let's discuss some common mistakes. If I forget a quote and write print(Hello, World!), what do you think will happen?
You will get a syntax error?
Exactly! Correct syntax is crucial. Always check for missing parentheses or quotes. Remember: Syntax Errors = Code Problems! Can anyone recall another type of common error?
A NameError might happen if I use a variable that isn't defined?
Great point! NameErrors show up when we try to use variables before they've been declared. Always check your variable names!
As we get accustomed to writing more complex programs, clear output messages become essential. If a user sees print('Error!'), how might that affect their understanding?
They might not know what went wrong!
Exactly! Instead of vague messages, we should aim to describe what happened clearly. Can anyone think of a clearer way to communicate the situation in code?
Maybe we could print out more descriptive messages, like 'Error: Invalid input'?
Perfect! Clear and descriptive output is a best practice in programming. Let's remember: Clarity = User-Friendly Code.
To print on screen, just add some quotes, a string appears — that's how it floats!
Imagine a magician who reveals words that appear when you say 'Abracadabra!' That's how the print() function works in Python; it makes your words appear!
Use P.E.Q.: Print outputs in Quotes to remember to always include quotes when using print().
P.O.S. = Print Outputs Strings, a reminder that print() works with strings.
Term
What does the print() function do?
Click to flip
Term
Define Syntax Error.
Click to flip
Term
What is a string?
Click to flip
A built-in Python function used to display text or other outputs on the screen.
An error that occurs when the code is incorrectly written, preventing it from executing.
A sequence of characters enclosed in quotes, used to represent text in programming.
A specific string represented in the code, such as 'Hello, World!'.
Integrated Development Environment, a software application that provides comprehensive facilities to programmers for software development.
In this section, you learn how to write your very first Python program by using the print() function to display a simple message.
This section introduces the concept of writing a basic Python program using the print() function. It emphasizes the simplicity and readability of Python, making it accessible for beginners aiming to learn coding.
In this section, we will dive into the very first step of programming in Python: writing a simple program to print a message to the screen. The example we will work with is print("Hello, World!").
Learning how to write your first Python program sets the foundation for all subsequent programming skills. It is a gateway to understanding more complex programming concepts.