An interactive introduction to programming in Python, for human beings and whoever else
Where are our manners?! We’ve been spending a lot of time asking Python intense math questions, but we never greeted her properly. Maybe we should say hello?
Okay, that… doesn’t seem right. We don’t know a lot about programming, but I’m pretty sure that’s some sort of error message!
We’ll figure out how to read errors later. For now, just know we did something wrong. You’re going to see error messages a lot when you’re learning to code, so it’s important to not be scared of them!
But why did we get an error? Well, remember how Python only knows about numbers? Words and sentences and stuff like that are special: when we talk about text with Python, we need to put it in quotes.
Wow, that’s nice of her to say hello back. Notice how we used double quotes but Python responded with single quotes?
Does double or single quotes matter? What if we try to use single quotes? I don’t know, let’s see! Trying things out is healthy: if we’re wrong our computer isn’t going to explode (…probably).
Okay, doesn’t seem to make a difference. You can use whichever kind of quotes you like. Say Goodbye to Python using either single or double quotes.
'Goodbye'and hit enter
It looks like we can use either single quotes or double quotes, but can we mix them? Maybe start with a
' and end with a
Oh. Well. Hm.
SyntaxError: EOL while scanning string literal? We don’t have a clue what that means, but let’s just guess it’s a very complex way of saying “no, you can’t mix quotation marks.”
Error messages try their best, but they aren’t always very understandable. We’ll become friends with them eventually, though.
If you really like to talk and want to use multiple words, you just put the quotation marks around the whole thing.
"I love bread"
Because sometimes it’s fun to disagree, use the console below to tell Python that you hate bread.
I hate bread. Maybe you tried
You hate bread? Sorry!
"I hate bread"or
'I hate bread'and press enter
Nothing too crazy, right?
“Wait a second!” you’re thinking and/or yelling. “We stopped using numbers and Python is still working! You said Python only knows math, and you lied!”
That’s… only a little bit true. If we want to get technical, inside of her computer brain, Python thinks about words as numbers. We might talk more about how that works later, but just know that Python can understand words whenever we put them in quotation marks.
“Just like when you’re quoting people in English?” you ask.
“Exactly.” I respond.
"Just like when you're quoting people in English?" "Exactly."
Now it’s your turn!
Make Python say
Hello, world!, because it’s basically a mandatory part of learning to code. Make sure you get the comma and the exclamation mark or it won’t count!
We learned that when you do something wrong, Python shows you an error message. They don’t usually make sense, but we shouldn’t be scared of them because they’re trying to help.
We also learned you can talk about words with Python by putting them in quotation marks, by doing
"something like this" or
'like this'. Double quotes and single quotes work the same, but you can’t mix them.