Your First Python Program: Hello World
Write your first Python program and understand the basic structure of Python code.
Know More Team
January 16, 2024
4 min read
PythonHello WorldBeginnerBasics
Your First Python Program: Hello World
The "Hello, World!" program is a traditional first program for beginners learning a new programming language. It's simple but demonstrates several important concepts.
The Classic Hello World
print("Hello, World!")
This single line does several things:
- Uses the
print()
function - Passes a string as an argument
- Outputs text to the console
Understanding the Code
The print()
Function
print()
is a built-in Python function- It displays output to the console
- It can accept multiple arguments
Strings
- Text in Python is called a string
- Strings are enclosed in quotes (single or double)
- Both
'Hello, World!'
and"Hello, World!"
are valid
Variations of Hello World
Multiple Arguments
print("Hello,", "World!")
Using Variables
message = "Hello, World!"
print(message)
Formatted Output
name = "Python"
print(f"Hello, {name}!")
Running Your Program
- Save the code in a file with
.py
extension - Open terminal/command prompt
- Navigate to the file location
- Run:
python filename.py
Common Mistakes
- Forgetting quotes around strings
- Missing parentheses for function calls
- Incorrect file extension
What's Next?
Now that you can run Python programs, you're ready to learn about:
- Variables and data types
- User input
- Basic operations
- Comments
Keep practicing with different variations of the Hello World program!
Table of Contents
Navigate the scroll
Reading Progress