Back to Chapters
Chapter Progress: 0 %0 / 4 Lessons Read
‹›

1. Introduction to Python

1.3 Your first program

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      🧒 The easy way

      print() is Python's loudspeaker. Whatever you put inside, it shouts on the screen.

      • Words go inside quotes: "hi".
      • Numbers go without quotes: 7.
      • Each print() starts a new line.

      Thumb rule: Want to see something? Put it inside print( ).

      Watch it run · 1

      Python
      print("I love Python")
      Result
      I love Python

      Watch it run · 2

      Python
      print(10 * 2)
      Result
      20

      A Python script is a plain text file whose name ends in .py, such as hello.py. Run it from its folder with python hello.py.

      Python reads a script from top to bottom, one line at a time:

      • rows = 4 stores the number 4 under the name rows
      • print("Rows loaded:", rows) shows the text and the value on screen
      • print() puts a space between the items you give it

      If something goes wrong, Python shows an error message. Read its last line first: it says what went wrong, and the line number says where.

      Parts of print("Rows loaded:", rows)

      • print → the function that shows output
      • "Rows loaded:" → text, inside quotes
      • rows → a variable, no quotes, so Python shows its value
      Must Know:

      Text needs quotes; variable names don’t. print("rows") shows the word rows, while print(rows) shows its value, 4.

      How it fits together

      1. Write hello.py
      2. Run python hello.py
      3. See the output

      Step through the code

      Python

      rows = 4print("Rows loaded:", rows)

      Output

      Rows loaded: 4

      Practice in Python

      Set rows to 7 and print Rows loaded: 7 using the variable.

      Expected output
      Rows loaded: 7

      Reference solution
      rows = 7
      print("Rows loaded:", rows)

      Question 1 · Easy

      rows = 4. What does print("Rows loaded:", rows) show?

      Question 2 · Medium

      rows = 4. What does print("rows") show?

      Question 3 · Hard

      A script has line 1: count = 5 and line 2: print(total). What happens?

      Key takeaways

      A script runs statements in order and can print a result to the terminal.

      Lesson 3 of 67

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousYour first program
      Save your progress free for 1 month. Start free · Log in