1
00:00:00,000 --> 00:00:03,990
There're basically two different kinds of numbers in Python.

2
00:00:04,000 --> 00:00:06,990
Let's go ahead and make a working copy of variables.py,

3
00:00:07,000 --> 00:00:14,990
and we'll look at them, variables-numbers.py.

4
00:00:15,000 --> 00:00:17,990
We'll open our working copy.

5
00:00:18,000 --> 00:00:22,990
And we'll go ahead and define a variable.

6
00:00:23,000 --> 00:00:25,990
And we'll give it a value.

7
00:00:26,000 --> 00:00:31,990
And then we'll print that variable and save and run.

8
00:00:32,000 --> 00:00:34,990
And you see we get that value.

9
00:00:35,000 --> 00:00:38,990
So what we have here is an integer type.

10
00:00:39,000 --> 00:00:47,990
So if I type num and I'll also have num, so we'll get both the type and the value,

11
00:00:48,000 --> 00:00:48,990
we'll go ahead and run that,

12
00:00:49,000 --> 00:00:52,990
and we see that its class is int, and its value is 42.

13
00:00:53,000 --> 00:00:59,990
If I say 42.0, now its type is going to be <class 'float' > 42.0.

14
00:01:00,000 --> 00:01:03,990
So those are the two different kinds of numbers in Python.

15
00:01:04,000 --> 00:01:07,990
You have integers, and you have floating point numbers.

16
00:01:08,000 --> 00:01:14,990
If I take an integer like this, and I say 42/ 9, I'm no longer going to have an integer.

17
00:01:15,000 --> 00:01:20,990
If I save this and run it, we'll see that I have class 'float' and that it is this

18
00:01:21,000 --> 00:01:24,990
real number with a whole lot of digits after the decimal point.

19
00:01:25,000 --> 00:01:30,990
If I want to get an integer division, I can use two slashes instead of one.

20
00:01:31,000 --> 00:01:36,990
And now what I'll get, instead of 4.66666, I will get just 4.

21
00:01:37,000 --> 00:01:40,990
You'll notice that it is not rounded up.

22
00:01:41,000 --> 00:01:47,990
So if I want it to be rounded, I can type round and get back the floating point

23
00:01:48,000 --> 00:01:52,990
division and save that and run it,

24
00:01:53,000 --> 00:01:54,990
and now we have it rounded up. It's a 5.

25
00:01:55,000 --> 00:01:58,990
I can give another argument to round it to how many digits I want it to round to.

26
00:01:59,000 --> 00:02:00,990
I can save that and run it.

27
00:02:01,000 --> 00:02:03,990
And now we have 4.67.

28
00:02:04,000 --> 00:02:10,990
In addition to the integer division with the two slashes, remember it was like this -

29
00:02:11,000 --> 00:02:13,990
if I save that and run it, we get the 4 -

30
00:02:14,000 --> 00:02:21,990
I might also want the remainder, which is also called modulo, and that's with the % sign.

31
00:02:22,000 --> 00:02:28,990
So if I save that and run it, I have 6. That's the remainder after you do that 42/9.

32
00:02:29,000 --> 00:02:33,990
It's 4 with a remainder of 6.

33
00:02:34,000 --> 00:02:40,990
If I have a floating point number, say 42.9, but I want to make sure that

34
00:02:41,000 --> 00:02:46,990
it's actually going to be read as an integer, I can say int of, like this, and

35
00:02:47,000 --> 00:02:48,990
save that and run it,

36
00:02:49,000 --> 00:02:51,990
and I get just the 42 part.

37
00:02:52,000 --> 00:02:57,990
Likewise, if I have an integer number and I want the floating point

38
00:02:58,000 --> 00:03:03,990
representation of it, I can say float like that and save that and run it.

39
00:03:04,000 --> 00:03:08,990
And I actually get a floating point representation of the integer 42.

40
00:03:09,000 --> 00:03:12,990
Float and int are actually object constructors.

41
00:03:13,000 --> 00:03:15,990
These are constructors for those classes.

42
00:03:16,000 --> 00:03:19,990
So when I say float 42, what I'm actually doing is I'm creating an object of

43
00:03:20,000 --> 00:03:24,990
type float, and I'm giving it an initial value of 42.

44
00:03:25,000 --> 00:03:26,990
That's getting passed to the constructor.

45
00:03:27,000 --> 00:03:30,990
So those are the basic ways that you can use and create integers and floating

46
00:03:31,000 --> 00:03:41,000
point numbers in Python 3.

