1
00:00:00,500 --> 00:00:01,890
Hi guys and welcome back.

2
00:00:01,890 --> 00:00:05,100
Just a quick video to tell you about Booleans.

3
00:00:05,100 --> 00:00:09,680
A Boolean is a value that can be either true or false.

4
00:00:09,680 --> 00:00:11,830
And we can use that to make decisions,

5
00:00:11,830 --> 00:00:13,900
for example, using Boolean logic,

6
00:00:13,900 --> 00:00:17,690
we can tell whether a user's age is over 18.

7
00:00:17,690 --> 00:00:20,060
Or whether the user's character in a game

8
00:00:20,060 --> 00:00:21,910
has pressed the up arrow.

9
00:00:21,910 --> 00:00:24,430
Things like that are what we need Booleans for

10
00:00:24,430 --> 00:00:26,100
and they are everywhere in Python

11
00:00:26,100 --> 00:00:27,180
and in Programming.

12
00:00:27,180 --> 00:00:28,580
Let's learn more about them.

13
00:00:29,730 --> 00:00:32,900
Booleans are created by using comparisons.

14
00:00:32,900 --> 00:00:34,650
So, you can compare two things together

15
00:00:34,650 --> 00:00:36,410
to calculate whether two things

16
00:00:36,410 --> 00:00:38,580
are the same or different,

17
00:00:38,580 --> 00:00:42,450
for example, if you print five equal equal five,

18
00:00:42,450 --> 00:00:45,000
this is a Boolean comparison,

19
00:00:45,000 --> 00:00:47,030
five equal equal five.

20
00:00:47,030 --> 00:00:48,680
Notice that a single equal sign

21
00:00:48,680 --> 00:00:51,370
is used to assign a value to a variable.

22
00:00:51,370 --> 00:00:53,420
But two equal signs, one after another

23
00:00:53,420 --> 00:00:56,210
are used to compare two things.

24
00:00:56,210 --> 00:00:57,700
And what we're comparing here is,

25
00:00:57,700 --> 00:00:59,740
five and we're gonna check whether it is

26
00:00:59,740 --> 00:01:02,520
exactly equal to five.

27
00:01:02,520 --> 00:01:04,630
So, these two numbers here are being compared

28
00:01:04,630 --> 00:01:06,290
and we're going to get true,

29
00:01:06,290 --> 00:01:07,820
if they are exactly equal

30
00:01:07,820 --> 00:01:09,470
and we're going to get false if they are

31
00:01:09,470 --> 00:01:11,250
in any way different.

32
00:01:11,250 --> 00:01:13,170
So, if I run this here, you'll see

33
00:01:13,170 --> 00:01:15,013
that we get true out.

34
00:01:17,540 --> 00:01:19,030
As well as equal equal,

35
00:01:19,030 --> 00:01:22,010
you can use the typical maths operators

36
00:01:22,010 --> 00:01:23,310
such as greater than,

37
00:01:23,310 --> 00:01:25,640
to calculate whether a number is greater than

38
00:01:25,640 --> 00:01:26,503
another number.

39
00:01:27,780 --> 00:01:29,483
And there you get false.

40
00:01:32,090 --> 00:01:34,162
As a special case, you've also got,

41
00:01:34,162 --> 00:01:37,360
exclamation mark equal, which is used

42
00:01:37,360 --> 00:01:39,900
to tell whether two things are different.

43
00:01:39,900 --> 00:01:41,520
So, what this reads as is,

44
00:01:41,520 --> 00:01:44,490
is 10 different from 10?

45
00:01:44,490 --> 00:01:47,220
So, again, you'll get true if they are different

46
00:01:47,220 --> 00:01:49,683
and you'll get false if the are not different.

47
00:01:50,950 --> 00:01:54,000
So, here we should get false,

48
00:01:54,000 --> 00:01:55,723
because they are not different.

49
00:01:57,030 --> 00:01:58,770
Other comparisons that are available

50
00:01:58,770 --> 00:02:00,880
as well as equal equal, not equal

51
00:02:00,880 --> 00:02:03,900
and greater than are less than

52
00:02:03,900 --> 00:02:05,590
and greater than are equal to,

53
00:02:05,590 --> 00:02:06,900
or less than are equal to.

54
00:02:06,900 --> 00:02:08,970
And this is how you write them in Python.

55
00:02:08,970 --> 00:02:10,280
So, you can check whether something is

56
00:02:10,280 --> 00:02:12,850
less than one thing, whether it's greater than

57
00:02:12,850 --> 00:02:14,170
or equal to something else

58
00:02:14,170 --> 00:02:15,260
or whether it's less than

59
00:02:15,260 --> 00:02:16,773
or equal to something else.

60
00:02:18,160 --> 00:02:18,993
I'll say at this point,

61
00:02:18,993 --> 00:02:20,850
that you can use these operations,

62
00:02:20,850 --> 00:02:22,530
not only on numbers,

63
00:02:22,530 --> 00:02:24,650
but on any other value including lists,

64
00:02:24,650 --> 00:02:26,730
and tuples and strings and what not,

65
00:02:26,730 --> 00:02:28,720
but they can behave differently depending

66
00:02:28,720 --> 00:02:31,270
on what type of data you use them on.

67
00:02:31,270 --> 00:02:32,300
We're going to learn more

68
00:02:32,300 --> 00:02:34,690
and get more acquainted with how they behave

69
00:02:34,690 --> 00:02:36,830
in different scenarios, as we go along

70
00:02:36,830 --> 00:02:39,590
with better examples, of course.

71
00:02:39,590 --> 00:02:41,590
So, these are the comparisons

72
00:02:41,590 --> 00:02:43,810
and as well as comparisons, you've also got

73
00:02:43,810 --> 00:02:45,080
a few Python key words

74
00:02:45,080 --> 00:02:47,663
that you can use to calculate Booleans.

75
00:02:49,300 --> 00:02:52,320
One of the more confusing key words in Python,

76
00:02:52,320 --> 00:02:53,780
when you're talking about Booleans

77
00:02:53,780 --> 00:02:56,370
is the ease key word.

78
00:02:56,370 --> 00:02:58,160
So, here we've got two list,

79
00:02:58,160 --> 00:02:59,870
friends and abroad and they have

80
00:02:59,870 --> 00:03:02,270
the exact same elements inside them.

81
00:03:02,270 --> 00:03:05,860
You can print whether friends equal equal abroad

82
00:03:05,860 --> 00:03:07,630
and when you run this code,

83
00:03:07,630 --> 00:03:09,460
you get back true,

84
00:03:09,460 --> 00:03:11,850
because the equal equal sign,

85
00:03:11,850 --> 00:03:14,500
when you're talking about two different lists,

86
00:03:14,500 --> 00:03:16,470
compares whether the elements inside them

87
00:03:16,470 --> 00:03:17,780
are the same.

88
00:03:17,780 --> 00:03:20,300
And here, because you're comparing two strings,

89
00:03:20,300 --> 00:03:22,070
then Python can detect

90
00:03:22,070 --> 00:03:24,383
that these two lists are actually the same.

91
00:03:25,300 --> 00:03:27,850
However, a lot of new Python developers

92
00:03:27,850 --> 00:03:30,470
will try to do friends is abroad,

93
00:03:30,470 --> 00:03:32,590
which is something you can do in Python.

94
00:03:32,590 --> 00:03:34,670
But you won't get what you expect

95
00:03:34,670 --> 00:03:36,630
because you get false.

96
00:03:36,630 --> 00:03:39,210
That is because when you create a new list,

97
00:03:39,210 --> 00:03:41,630
Python goes and creates some space

98
00:03:41,630 --> 00:03:44,370
in its memory for this new list.

99
00:03:44,370 --> 00:03:46,660
The elements can be stored somewhere else,

100
00:03:46,660 --> 00:03:50,313
but the list itself has its own area in memory.

101
00:03:51,260 --> 00:03:53,580
Then when you create another list,

102
00:03:53,580 --> 00:03:56,080
it goes and creates another area in memory

103
00:03:56,080 --> 00:03:57,810
for this other list.

104
00:03:57,810 --> 00:04:01,130
The elements inside the list were created separately

105
00:04:01,130 --> 00:04:03,920
and they could be the same between both lists,

106
00:04:03,920 --> 00:04:07,210
but the lists themselves are different.

107
00:04:07,210 --> 00:04:10,450
And that is what the is keyword checks in Python.

108
00:04:10,450 --> 00:04:14,050
It checks whether two elements are exactly the same thing,

109
00:04:14,050 --> 00:04:16,870
not whether they have the same elements inside them

110
00:04:16,870 --> 00:04:19,000
or whether they are similar.

111
00:04:19,000 --> 00:04:21,180
So, again the is keyword is to compare

112
00:04:21,180 --> 00:04:23,800
whether two elements are the same thing.

113
00:04:23,800 --> 00:04:26,750
So, if you do friends is friends, for example,

114
00:04:26,750 --> 00:04:28,663
you're going to get true.

115
00:04:29,780 --> 00:04:33,040
If say abroad equal friends up here

116
00:04:33,040 --> 00:04:35,450
and then you check whether friends is abroad,

117
00:04:35,450 --> 00:04:37,280
you're also going to get true

118
00:04:37,280 --> 00:04:39,740
because you haven't created two lists.

119
00:04:39,740 --> 00:04:42,360
You've just pointed the two variables

120
00:04:42,360 --> 00:04:43,780
to the same list.

121
00:04:43,780 --> 00:04:46,490
And that again is what the is keyword is for,

122
00:04:46,490 --> 00:04:48,920
I recommend you almost never use it.

123
00:04:48,920 --> 00:04:50,680
You're almost always gonna want to use

124
00:04:50,680 --> 00:04:51,803
the double equal sign.

125
00:04:52,930 --> 00:04:54,660
All right, that's it for comparisons

126
00:04:54,660 --> 00:04:56,660
and this brief introduction to Booleans.

127
00:04:56,660 --> 00:04:58,550
Let's learn more in the next video.

128
00:04:58,550 --> 00:04:59,500
I'll see you there.

