Hello, and welcome back. In this we’re going to dive a little more in depth on the atoms, the nuggets, the little pieces that make up Python. And then we’re going to work though our first real program that has a sort of beginning, middle, and end. So, here we go.
A big part of any programming language is the syntax for constants. The nice thing about this it’s kind of instinctive. So, like a 123 or 98.6, numbers both integer and floating point numbers. We’ve been using this on calculators. They make a lot of sense to us. The kind of constants that are a little bit different are things like string constants. So “Hello world” is a string constant. We use that so that our program can say nice things to people that are using our program. And so, we call them constants because they don’t change but it’s kind of obvious, constants. It’s just a piece of the language, so that’s a constant. What else? Variables and reserved words. So the other thing other than constants are reserved words.
And you get to pick the variable names. And it’s a little weird that you get to pick variable names, but you’ll get used to it. And so variable names are places where you’re asking Python to allocate a bit of memory and stick something in it and you’re choosing the label. And so if we take a look at this. When we have this assignment statement, and remember that assignment statements always have a direction, right? Think of these equal signs as having an arrow on them. In some languages, I saw a language that uses kind of an arrow that uses a less than and a dash as the assignment. I went, that’s how it should be because equal confuses us. Because equal means something different in mathematics than it does in Python or other programming languages.
So look at this very first statement. What we’re really saying is, it’s a pretty complex statement. After a while, you’ll just use it. Python, find us a spare piece of memory somewhere and give it a label of x, and put 12.2 in it. And remember that, remember all that stuff. That’s one of things that Python does for us, it remembers stuff. Then we go to the second statement. It says oh, hey Python, find some spare memory that you got laying around, label it y and put 14 into that, okay? And so that’s how these things work and you chose x and you chose y.
Now if we keep on going in this code, and now we have another line and we say oh, hey, x, wait a sec. I already told you about x, x already exists so don’t go out and grab any new memory, but stick 100 in that. So 100 goes in and it wipes out the old value. So, that’s what happens. When this sequence starts, this happens first, second, third. And so the third thing is the last thing and so x ends up with a residual value of 100 in it. So that’s kind of variables and assignment statements. You have some naming rules. You can start variable names with letters or underscores, although we avoid underscores because Python tends to use underscores for its own internal purposes.
Okay, so that gets us through variables and constants and next we will talk about expressions.