Python First Program
In this page:
The print() Function
print() is the built-in function that writes output to the screen — pass it text, a number, or a variable, and it displays the result followed by a newline. It's the fastest way to see what your code is actually doing while you're learning.
Example: The print() Function
print("Hello, World!")
Basic Strings
Python treats text wrapped in either single or "double" quotes identically as a str value, so you can pick whichever avoids awkward escaping (for example, using double quotes for a string that itself contains an apostrophe). Both forms are functionally interchangeable.
Example: Basic Strings
print('Hello')
print("Hello")
print("It's a good day")
Standard Calculations
Because print() evaluates its argument before displaying it, you can write print(2 + 3) directly and Python will compute 5 and show that, without a separate calculation step first. This is a quick way to sanity-check arithmetic while experimenting.
Example: Standard Calculations
print(2 + 3)
Variables in Action
A variable is created the moment you assign it a value with =, and passing that variable's name to print() displays whatever it currently holds. Because Python is dynamically typed, the same variable can be reassigned to a different type later without any special syntax.
Example: Variables in Action
value = 10
print(value)
value = "ten"
print(value)
Running the Program
Once your first script runs cleanly, it's worth deliberately introducing a typo (like a missing parenthesis) to see what a Python error message looks like — recognizing common errors early makes debugging far less intimidating once your programs grow.
Example: Running the Program
# Missing closing parenthesis -- try running this to see the error
print("Hello"
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: