No history yet

Python Basics

Transcript

Beau

Okay, so. Last time, we got everything set up. Python is installed, I have this… this VS Code thing open, and I'm staring at a blinking cursor. It feels both powerful and, uh, terrifying.

Jo

The blank page! I know the feeling. But that cursor is where it all starts. The first thing we need to do is give the computer something to remember. That's where variables come in.

Beau

Variables. Okay, that sounds like math class. I'm already getting nervous.

Jo

It's way simpler, I promise. Think of a variable as a labeled box. You can put something inside the box, and you write a name on the outside so you can find it later. That's it.

Beau

A labeled box. I can work with that. So… how do I make one? Do I have to tell the computer I need a box?

Jo

Nope, Python is smart. You just name it and put something in it at the same time. So, you could type, say... `player_score = 100`. You've just created a variable named `player_score` and you've put the number 100 inside.

Beau

Oh, okay. The equals sign is like the 'put into' operator. So, `player_score` gets 100. I see. And I can name it anything? Like `beau_is_awesome = 100`?

Jo

Pretty much. There are a few rules, like it can't start with a number and no spaces, but yeah, `beau_is_awesome` is a totally valid variable name. This process is called assignment. You're 'assigning' the value 100 to the variable.

Beau

Got it. So what kind of stuff can I put in these boxes? Is it just numbers?

Jo

Great question. That brings us to data types. The 'type' of thing you're putting in the box. The number 100 is what's called an integer. A whole number.

Beau

Integer. Right. Like 1, 2, 3, minus 50.

Jo

Exactly. But what if you were tracking, I don't know, a stock price? It wouldn't be just 150, it would be 150.75 or something.

Beau

Ah, right. Decimals.

Jo

Yep. In Python, those are called floating-point numbers, or just floats. So `stock_price = 150.75` would store it as a float. Integers are for counting things, floats are for measuring things.

Beau

Okay, that's a good way to put it. Integers for counting, floats for measuring. What else we got?

Jo

Well, what about text? Like a player's name? For that, you use strings. A string is just any sequence of text inside quotes. So you could have `player_name = "Beau"`.

Beau

String. Like a string of characters. Makes sense. So, wait, what if I did `my_number = "5"` with quotes around it? Is that the same as `my_number = 5`?

Jo

Excellent question. No, they are completely different. `my_number = 5` is an integer. The computer knows it's a value; you can do math with it. You could say 5 plus 5 and get 10. But `my_number = "5"` is a string. The computer just sees the character '5'. If you tried to add '5' plus '5', you'd get '55'.

Beau

It would just... stick them together? Like glue?

Jo

Exactly. That's called concatenation. It's super useful for text, but a nightmare if you think you're working with numbers. So the data type is really important.

Beau

Okay, so we have integers for whole numbers, floats for decimals, strings for text. Is that everything?

Jo

There's one more really fundamental one: the boolean. It's... it's a weird one at first, but it's maybe the most important.

Beau

Boolean... lay it on me.

Jo

A boolean can only have two possible values: `True` or `False`. That's it. It's like a light switch—it's either on or it's off. There's no in-between.

Beau

Oh! So for a game, I could have `is_player_alive = True`. And if they, y'know, run into a spike trap, I could change it to `is_player_alive = False`.

Jo

You've got it. That's a perfect use case. Or for your stock trading algorithm, `is_market_open = True`. Booleans are the foundation of all decision-making in code. We'll rely on them heavily later.

Beau

Okay, this is making sense. I have these labeled boxes, and I can put different types of things in them. But... how do I see what's in a box? Or, like, make the program talk to me?

Jo

That's the output part of 'input and output'. The command for that is beautifully simple: `print`. You just type `print()` and put whatever you want to see inside the parentheses.

Beau

So if I had `player_score = 100`, I would just write `print(player_score)`?

Jo

And when you run the script, the number 100 will just appear on your screen. It's how you check the state of your program, see results, or display messages.

Beau

Okay, printing stuff out. Check. What about the other way? Getting input *from* the user?

Jo

Also very straightforward. The command is `input()`. It pauses the program, waits for the user to type something and hit Enter, and then it returns whatever they typed.

Beau

Returns it... so it just kinda spits it out? Where does it go?

Jo

It needs to be stored somewhere! This is where variables and functions connect. You assign the result of the `input` function to a variable. So you'd write `user_name = input("Please enter your name: ")`.

Beau

Whoa, okay, break that down. The part in quotes is the prompt, right? The message it shows me?

Jo

Correct. It'll display 'Please enter your name: ' and then wait. If you type in 'Beau' and press Enter, the string 'Beau' gets put inside the `user_name` variable. Then you could follow it up with `print(user_name)` to see it work.

Beau

I see! So I could write a tiny program right now that asks for my name and then says hello back to me or something.

Jo

You absolutely could. And that's... that's programming. At its core, it's just getting data, storing it in variables, and then doing things with it. You've got the first two steps down.

Beau

Okay, that blinking cursor feels a little less terrifying now. A little bit.