Rock Solid Python with Python Typing Transcripts
Chapter: Typing in Python
Lecture: Survey of Core Types

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Continuing on, we're now going to do a quick survey of the core types in Python. You've already seen that we can have integers like 27.
0:10 We also can be more explicit about the type of numbers we can work with.
0:15 We could say we have a floating point, something approximating the square root of 2. We could even say we want a complex number,
0:28 where we specify the imaginary and real parts. So for the imaginary part we could have 0, and here we could have -v, for example.
0:38 So -sqrt, let's print some of these out, u, v, c. They use j, come on, we all know it's supposed to be i.
0:48 But there's our numbers, right? We got those back. We can have some text, like this. This could be some text.
0:58 We could also have bytes and bytes and strings used to be real real similar. So we could say this is equal to B of bytes text.
1:07 So the raw here, there's a lot of ways to express different strings as raw strings and other types of strings. But bytes is a separate thing here.
1:16 Just, you know, the bytes representing those ASCII codes. We have a bunch of container types.
1:21 we have a LST, which might be the list one, one, two, three, five, eight, just randomly
1:26 picking numbers out of the air. Or it could even be a set, which would be a set of or
1:33 you could express it like this, these same numbers, which will remove the duplication
1:39 and be one, two, three, five, five and eight. Let's go and print out all these new things.
1:45 Here you go and see the set is remove the duplicates here you can have the bytes as
1:49 B. Now, none of these have explicit types. So let's go and add them. And if we get them
1:54 wrong, PyCharm should let us know like, ""Oh, we expected an int, but we got a floating
2:00 point number."" Okay. And here, it's a little more obvious because it says the type right
2:05 there, isn't it? And this is going to be a string or as Python represents it, just str.
2:11 And this will be a bytes. So be a list. We'll talk more about what goes in the list. This
2:17 This would be a set, right? These are the alternate ways the class types for these things.
2:23 One more we could add in here, maybe it'd be fun would be truth, which could be true or false.
2:28 And that's going to be a Boolean. Super, super important. And where's it go in the list right
2:32 there. Truth. So those are our different types. And you can see, if we were to try to assign one
2:38 to the other, lst equals s, we know that one of these variables of type set the others list,
2:45 they don't go together because there's no type hierarchy between those two types there.
2:50 All right, so these are the core types in Python. There are many, many more types in the standard
2:56 library and nearly unbounded many if you start looking into the external packages on PyPI.
3:02 But these are the ones you're going to be working with all the time.


Talk Python's Mastodon Michael Kennedy's Mastodon