Hello, World! 👋
What You'll Learn
- Write and run your first Python program
- Understand what print() does
- Use comments in Python
Your First Line of Code
By tradition, the first program every coder writes just prints the words "Hello, World!" to the screen. Let us do that right now!
print("Hello, World!")Type that in your Python editor and press Enter (or click Run). You should see:
Hello, World!
You just wrote your first Python program! Every professional coder started exactly where you are right now.
The print() Function
print() is a built-in Python function that displays text on the screen. Whatever you put inside the parentheses (in quotes) gets printed. Try these:
print("Hello, Oklahoma!")
print("I am learning to code!")
print("Python is awesome!")Comments — Notes in Your Code
A comment starts with a # symbol. Python ignores everything after # on that line. Use comments to explain your code:
# This is my first Python program
print("Hello, World!") # This prints a greetingProfessional programmers write comments so other people (and their future selves!) can understand the code.
Modify the Hello World program to:
- Print your name
- Print your city
- Print your favorite animal
- Add a comment above each print() explaining what it does
What does the print() function do?
How do you start a comment in Python?
What is printed by: print(42)?