Lesson 1: Introduction to Python#

Welcome to your first programming lesson! Python is a beginner-friendly programming language thatโ€™s:

  • Easy to read: Looks almost like English

  • Powerful: Used by Google, Netflix, NASA, and more

  • Versatile: Web development, data science, AI, automation, games

What Youโ€™ll Learn#

  • How to run Python code

  • Printing messages to the screen

  • Comments and documentation

  • Your first programs


1. Hello, World!#

The traditional first program in any language is to print โ€œHello, World!โ€ to the screen.

Click on the cell below and press Shift+Enter to run it:

print("Hello, World!")

๐ŸŽ‰ Congratulations! You just ran your first Python program!

How it works:#

  • print() is a function that displays text

  • The text inside quotes ("Hello, World!") is called a string

  • Strings must be wrapped in quotes (single ' or double ")


2. Printing Different Messages#

You can print anything you want:

print("Python is awesome!")
print("I am learning to code")
print("2024")

โœ๏ธ Try It Yourself#

Modify the code below to print your own message:

# Type your code here
print("Your message here")

3. Comments#

Comments are notes in your code that Python ignores. They help you and others understand your code.

Use # to create a comment:

# This is a comment - Python ignores this line
print("This runs")  # You can add comments after code too

# print("This won't run because it's commented out")

๐Ÿ’ก Pro Tip:#

Good programmers use comments to explain why code does something, not just what it does.


4. Printing Multiple Lines#

You can print multiple lines in different ways:

# Method 1: Multiple print statements
print("First line")
print("Second line")
print("Third line")
# Method 2: Using \n (newline character)
print("First line\nSecond line\nThird line")
# Method 3: Triple quotes for multiple lines
print("""
First line
Second line
Third line
""")

5. Printing with Separators#

The print() function can print multiple items:

# Print multiple items (separated by space by default)
print("Hello", "World")
print("Python", "is", "fun")
# Custom separator
print("Python", "Java", "JavaScript", sep=" | ")
print("2024", "10", "30", sep="-")

6. Printing Numbers#

You can print numbers without quotes:

print(42)
print(3.14)
print(2 + 2)  # Python evaluates math first
print("The answer is:", 42)  # Mix text and numbers

โš ๏ธ Common Mistake:#

print("2 + 2")  # This prints the text "2 + 2"
print(2 + 2)     # This calculates and prints 4

7. Simple ASCII Art#

You can create simple drawings using print statements:

print("  *  ")
print(" *** ")
print("*****")
print(" ||| ")
# A simple face
print("  O O  ")
print("   ^   ")
print("  \_/  ")

๐Ÿ“ Exercises#

Exercise 1: Personal Introduction#

Create a program that prints:

  • Your name

  • Your age (or any number)

  • Your favorite hobby

Each should be on a separate line.

# Your code here

Exercise 2: Math Display#

Print the following calculations (let Python do the math):

  • 15 + 27

  • 100 - 42

  • 8 * 7

Make it look nice with labels, like: "15 + 27 =" followed by the answer.

# Your code here

Exercise 3: Create ASCII Art#

Create your own simple ASCII art! Ideas:

  • A house

  • A car

  • Your initials

  • An animal

Get creative!

# Your ASCII art here

Exercise 4: Story Printer#

Write a short 5-line story using print statements. Make it interesting!

# Your story here

Exercise 5: Pattern Challenge#

Print this pattern:

*
**
***
****
*****
# Your code here

โœ… Self-Check Quiz#

Before moving on, make sure you can answer these:

  1. What function do we use to display text in Python?

  2. What are strings, and how do you write them?

  3. How do you create a comment in Python?

  4. Whatโ€™s the difference between print(2 + 2) and print("2 + 2")?

  5. How do you print multiple items on one line?


๐ŸŽฏ Key Takeaways#

  • print() displays text and numbers

  • Strings are text wrapped in quotes: "like this" or 'like this'

  • Comments start with # and are ignored by Python

  • You can print multiple items separated by commas

  • Python can do math inside print() statements


๐Ÿš€ Next Steps#

Great job! Youโ€™ve learned the basics of Python output. Next, youโ€™ll learn about variables - how to store and reuse information.

Continue to: 02_variables_and_data_types.ipynb


๐Ÿ’ฌ Did You Know?#

Python was created by Guido van Rossum in 1991 and named after the comedy group โ€œMonty Pythonโ€ - not the snake! ๐Ÿ