Day 3 · ~14m

What is Python?

Your first steps with Python — what it is, how it runs code, and your first function.

🧑‍💻

OK so I keep hearing "learn Python" from everyone at work. My manager said it could help me automate my reports. But I literally have no idea what Python even is. Is it like a fancier version of Excel?

👩‍🏫

Not quite. Excel is a tool — somebody built it so you could organize data in rows and columns. Python is a programming language. It's the kind of thing someone would use to build a tool like Excel. When you write Python, you're writing plain text instructions that a computer reads and executes, one line at a time.

Here's a complete Python program:

print("Hello!")

That's it. One line. It tells the computer: display the text Hello! on screen. Python reads the line, runs it, and you see the output. No buttons, no menus — just text in, result out.

🧑‍💻

Wait, that's really it? I was expecting something way more complicated. So it's basically... writing instructions in a text file?

👩‍🏫

Exactly. And the reason people love Python specifically is that those instructions look almost like English. Check this out:

if age >= 18:
    print("You can vote")

You can read that out loud: "If age is greater than or equal to 18, print 'You can vote'." Compare that to what most programming languages look like and you'll see why Python is where most people start. The readability isn't a gimmick — it means you spend your time thinking about what to do, not how to say it.

🧑‍💻

OK, makes sense so far. But printing text to a screen isn't exactly going to help me with my quarterly reports. How do I make Python actually do something useful?

👩‍🏫

You write functions. A function is a reusable block of code with a name. Think of it like a formula in your spreadsheet — you define it once, and then you can use it over and over. Here's the simplest possible function:

def greet():
    return "Hello!"

Let me break that down:

  • def means "I'm defining a function"
  • greet is the name you chose — like naming a cell range in Excel
  • return sends a value back to whoever called the function

When you call greet(), Python runs the code inside and hands you back "Hello!".

🧑‍💻

OK I think I follow, but what's the difference between print and return? They both seem to produce output.

👩‍🏫

This is the question that trips up everyone in their first week, so let's get it straight now.

  • print() displays text on screen. It's for you to see what's happening.
  • return sends a value back to the program. Other code can use it.
def get_score():
    return 95       # The program gets 95 back — it can use this number

def show_score():
    print(95)       # You see 95 on screen, but the program gets nothing back

Imagine you ask a coworker, "What were last quarter's sales?" If they show you the number on their screen, that's print. If they hand you the number so you can put it in your own spreadsheet, that's return.

🧑‍💻

Oh, that actually makes sense. So True and False — I saw those in the quiz. Those are Python things?

👩‍🏫

Yes — they're called booleans. Python has exactly two: True and False (always with a capital T and F). They represent yes/no, on/off, pass/fail. Every time your code asks a question — "is this number bigger than 10?", "did the user log in?" — the answer is a boolean.

def is_raining():
    return True

def is_sunny():
    return False

So now you've got the three building blocks: def to create functions, return to send values back, and True/False for yes/no answers. Let's see if you can put them together.

Practice your skills

Sign up to write and run code in this lesson.

Already have an account? Sign in