Python for Absolute Beginners Transcripts
Chapter: Writing your first lines of code
Lecture: Concept: Variables and types

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review this idea of variables data values, and types. We saw that we can create variables
0:07 just by saying their name, and then giving them a value. Though, in our Python REPL, Read, Eval, Print, Loop we were able to type x = 42.
0:16 Notice this green dip with a hash in Python you can make comments that are meant for people that have no effect on how code runs.
0:23 So we're going to say hash if we were to run Typhon X but what we'd get back is this class inch. Remember we said there's a way in Python to ask
0:32 What type of data are we working with? And here when you work with whole numbers in Python that's an integer.
0:38 We came up with another variable, 19, also an integer then we saw we can use them in expressions like what is x + 7 * y?
0:48 Then if we don't assign it to a value that just kicks out whatever the response or the evaluation, the value of it is, so 175.
0:55 We can also create text base data and these are strings. They go in single quotes, or double quotes. Like we have here, so we said name = 'Michael'.
1:05 Now if we asked the type again this one has changed from int to str. And you can combine strings and numbers by adding them together
1:14 but if you try to mix these types it doesn't really like it so much. Here we saw that there was an error if we said name + x. We got an exception.
1:22 The program sort of crashed and if it was a real program that we were running it wouldn't continue, it would just stop and say
1:27 Something's broken, we're done. But in the REPL it just prints out the error and carries on. If we didn't want to combine numbers and strings
1:35 we can use a format string. We know we have a format string because it has that little f at the beginning. So here we say, Hi, pearly name.
1:43 And that just takes the value, currently Michael. Looks like you did math, and then we want to restate the equation and then the value.
1:49 So x, {x + 7 * y} is going to be whatever that value is. Now, I could've assigned that response or that evaluation to a variable.
2:01 We could've said something like z = x + 7 * Y and that's probably the best thing to do actually. But I wanted to make the point
2:09 that it's not just variables that can go into these format strings inside those curly braces. More general Python expressions can go in there.
2:17 So, if you wanted to compute something or you wanted to call a function get some behavior out of a piece of data we'll see how to do that later.
2:24 You can do that there. So, these are very very flexible. And we run this code, we get Hey Michael looks like you did math, 42 + 7 * 19 is 175.
2:35 Aright, so here we've created a bunch of variables we've set their data and we've set their data values which implies a data type.
2:42 We saw that we don't say the type in Python but that it is important to know about it. Like for example, name plus X, we should know
2:49 that we can't do those things. We need to do the thing at the bottom. Create that cool little string that we got in the end.


Talk Python's Mastodon Michael Kennedy's Mastodon