1
00:00:01,060 --> 00:00:07,420
Programming often involves examining a set of conditions and deciding which action to take based on

2
00:00:07,420 --> 00:00:08,440
these conditions.

3
00:00:08,470 --> 00:00:15,580
Python's If statement allows you to examine the current state of a program and respond appropriately

4
00:00:15,580 --> 00:00:16,510
to that state.

5
00:00:16,540 --> 00:00:22,660
In this section, you will learn to write conditional tests which allow you to check any condition of

6
00:00:22,660 --> 00:00:27,970
interest, and you will learn to write simple if statements and you will learn how to create a more

7
00:00:27,970 --> 00:00:35,320
complex series of if statements to identify when the exact conditions you want are present, and you

8
00:00:35,320 --> 00:00:41,410
will then apply this concept to lists and so you will be able to write a for loop that handles most

9
00:00:41,410 --> 00:00:47,070
items in a list one way, but handles certain items in a with specific values in different way.

10
00:00:47,080 --> 00:00:57,440
So this example here we will show the if tests that let you respond to special situations correctly.

11
00:00:57,460 --> 00:01:02,810
Imagine you have a list of cars and you want to print out the name of each car.

12
00:01:02,810 --> 00:01:04,910
So car names are proper names.

13
00:01:04,910 --> 00:01:09,440
So the names of most cars will be printed in title names title case.

14
00:01:09,470 --> 00:01:16,160
However, the value BMW here should be printed in all uppercase and here we will.

15
00:01:16,160 --> 00:01:17,900
Which we will do that right now.

16
00:01:17,900 --> 00:01:23,120
So we will car makers, car makers here.

17
00:01:23,120 --> 00:01:25,130
And after that we will equal to.

18
00:01:25,160 --> 00:01:33,680
So first we will enter the Volkswagen, the BMW, the Toyota, Toyota.

19
00:01:37,020 --> 00:01:37,710
Port.

20
00:01:38,650 --> 00:01:39,430
And.

21
00:01:41,760 --> 00:01:49,740
And here we will use the four car in car makers and here.

22
00:01:49,740 --> 00:02:02,430
So if car equals to BMW, then we will print the car dot upper and else here we will.

23
00:02:02,460 --> 00:02:07,650
Else we will print the car dot title.

24
00:02:07,650 --> 00:02:08,550
That's it.

25
00:02:08,550 --> 00:02:10,500
So now let's run it.

26
00:02:10,890 --> 00:02:11,460
That's it.

27
00:02:11,460 --> 00:02:12,090
Here.

28
00:02:12,360 --> 00:02:12,680
Oops.

29
00:02:13,050 --> 00:02:17,820
If BMW oops if BMW, that's it.

30
00:02:18,180 --> 00:02:20,130
Now this will work here.

31
00:02:21,450 --> 00:02:24,240
So now the loop in this example.

32
00:02:24,240 --> 00:02:25,260
First checks.

33
00:02:25,260 --> 00:02:32,460
If the current value of a car, if the current value of a car is BMW.

34
00:02:33,760 --> 00:02:39,440
If it is, the value is printed in uppercase here with this function.

35
00:02:39,460 --> 00:02:40,030
Right.

36
00:02:40,300 --> 00:02:47,050
If the value of a car is anything other than a BMW, it is printed in a title case.

37
00:02:47,170 --> 00:02:49,840
And here this is our output here.

38
00:02:50,020 --> 00:02:58,000
All of these names are written in title case, but here BMW is written in uppercase.

39
00:02:58,000 --> 00:03:02,730
So this example combines the number of concepts you will learn about in this section.

40
00:03:02,740 --> 00:03:09,220
Let's begin by looking at the kinds of tests you can use to examine the conditions in your program,

41
00:03:09,220 --> 00:03:12,850
so we can also use conditional tests in Python.

42
00:03:12,850 --> 00:03:18,820
So at the heart of every if statement is an expression that can be evaluated as true.

43
00:03:19,060 --> 00:03:20,800
As true.

44
00:03:22,630 --> 00:03:24,460
Or false, Right?

45
00:03:29,990 --> 00:03:41,630
So Python uses the values true and false to decide to decide whether the code is in a if statement should

46
00:03:41,630 --> 00:03:42,950
be executed or not.

47
00:03:42,980 --> 00:03:46,550
So if a conditional test evaluates true.

48
00:03:47,470 --> 00:03:52,240
Then Python executes the code following the if statement.

49
00:03:52,240 --> 00:03:54,550
So if the test evaluates false.

50
00:03:54,910 --> 00:03:58,540
If python ignores the code following the if statement.

51
00:03:58,930 --> 00:04:00,490
We can also check for equality.

52
00:04:00,490 --> 00:04:06,130
So the most conditional test compare the current value of a variable to a specific value of interest.

53
00:04:06,130 --> 00:04:13,990
So the simplest conditional test check test checks whether the value of a variable is equal to the value

54
00:04:13,990 --> 00:04:14,860
of interest.

55
00:04:14,890 --> 00:04:20,350
In order to do that, we will just delete for now our for loop and we will print here.

56
00:04:20,740 --> 00:04:25,870
Now car equals BMW here.

57
00:04:26,050 --> 00:04:31,120
Or let's actually, instead of writing that, let's use car makers.

58
00:04:31,120 --> 00:04:36,370
BMW index is one BMW and BMW here.

59
00:04:36,610 --> 00:04:41,740
So now as you can see we got an error cannot assign to a function call.

60
00:04:41,740 --> 00:04:46,480
So here that is we're going to get an error if we try to do that.

61
00:04:46,480 --> 00:04:50,960
However, if you try this in Python console, which we will now.

62
00:04:52,850 --> 00:04:53,270
Here.

63
00:04:53,270 --> 00:04:54,650
We opened our python.

64
00:04:54,650 --> 00:04:59,090
Now you can reach this by using just python.

65
00:05:00,900 --> 00:05:05,070
And here you're going to see this python 64 bit or 32 bit.

66
00:05:05,100 --> 00:05:09,450
You just enter that and here you can see the new tab opened.

67
00:05:09,480 --> 00:05:12,050
Here, let's actually make it closer.

68
00:05:12,060 --> 00:05:13,290
So most conditional.

69
00:05:13,290 --> 00:05:17,940
Let's ah, compare the current value of a variable to a specific value of interest.

70
00:05:17,970 --> 00:05:22,170
Let's create a new value named car here and make it BMW.

71
00:05:22,410 --> 00:05:26,850
And after that we will check the is car equal to BMW.

72
00:05:26,880 --> 00:05:30,730
And here you can you can see we got true.

73
00:05:30,750 --> 00:05:34,530
So the first line here actually, let me get this.

74
00:05:34,530 --> 00:05:38,010
So this first line, let me fix this.

75
00:05:38,040 --> 00:05:41,190
Now here, this first line here.

76
00:05:42,330 --> 00:05:44,250
Sets the value of a car.

77
00:05:44,890 --> 00:05:51,880
Car sets the value of a car to be actual b m.

78
00:05:51,880 --> 00:05:52,840
W.

79
00:05:54,320 --> 00:05:56,720
Using a single equal sign.

80
00:05:56,720 --> 00:06:00,860
So here we use the single equal sign here.

81
00:06:00,860 --> 00:06:01,460
Right?

82
00:06:02,860 --> 00:06:05,770
As you've seen many times already, this sign.

83
00:06:05,770 --> 00:06:12,460
So the next line checks the whether the value of a cars is BMW.

84
00:06:12,490 --> 00:06:14,590
Here you see here.

85
00:06:16,000 --> 00:06:16,950
Of sexual issues.

86
00:06:16,960 --> 00:06:18,310
Different color here.

87
00:06:21,540 --> 00:06:27,630
So now we are checking this by using a double equal sign.

88
00:06:28,170 --> 00:06:30,360
Double equal sign.

89
00:06:32,120 --> 00:06:32,660
Here.

90
00:06:33,020 --> 00:06:34,010
Car.

91
00:06:35,450 --> 00:06:36,280
Is.

92
00:06:37,700 --> 00:06:38,540
We?

93
00:06:39,440 --> 00:06:40,940
And W.

94
00:06:42,150 --> 00:06:46,830
So this is the equality operator.

95
00:06:46,950 --> 00:06:54,090
So and so this equality operator here, this is this is named equality Operator.

96
00:06:54,090 --> 00:06:57,150
Let me actually write that here.

97
00:06:57,180 --> 00:06:59,880
This is equality.

98
00:07:06,160 --> 00:07:07,120
Operator.

99
00:07:12,950 --> 00:07:18,710
So here this equality operator returns true, like in this case.

100
00:07:19,780 --> 00:07:25,030
If the values on the left and the right side of the operator match in this case, these are match.

101
00:07:25,030 --> 00:07:28,420
So car is actually equals to BMW.

102
00:07:28,450 --> 00:07:30,400
Actually, let me use the different color.

103
00:07:30,400 --> 00:07:35,500
So here our car is equals to BMW here.

104
00:07:36,480 --> 00:07:39,240
Because we already assign that in first line.

105
00:07:39,240 --> 00:07:43,410
And our BMW here equals to BMW, Right.

106
00:07:43,800 --> 00:07:52,500
So we are checking this BMW W and here they match.

107
00:07:52,530 --> 00:07:55,710
In this case, they will return.

108
00:07:55,740 --> 00:07:56,490
True.

109
00:07:58,310 --> 00:07:59,150
That's it.

110
00:07:59,570 --> 00:08:02,600
But here the values in this example.

111
00:08:02,600 --> 00:08:03,500
Match.

112
00:08:03,500 --> 00:08:04,160
Match.

113
00:08:04,160 --> 00:08:06,830
So Python returns true.

114
00:08:07,130 --> 00:08:15,380
So when the value of a car is anything other than a BMW, for example, let's try car equals equal the

115
00:08:15,620 --> 00:08:27,590
jeep here we will get false if car equal equal uppercase B M-W We will get false again because these

116
00:08:27,590 --> 00:08:34,580
equations equalization equation equality operator are case sensitive in strings.

117
00:08:34,580 --> 00:08:42,830
So here if we try something ice cream, ice cream, we will get false again.

118
00:08:43,450 --> 00:08:44,290
So.

119
00:08:45,450 --> 00:08:47,910
That's it here with operator.

120
00:08:47,910 --> 00:08:51,150
So a single equal sign is really a statement.

121
00:08:51,150 --> 00:08:58,410
And you might read the first line of a code here that we are setting a set the value of a car equal

122
00:08:58,410 --> 00:08:59,010
to.

123
00:09:00,440 --> 00:09:00,670
It.

124
00:09:00,860 --> 00:09:07,100
For example, Jeep, on the other hand, a double equal sign ask asks a question.

125
00:09:07,100 --> 00:09:08,900
Let me actually write it down.

126
00:09:09,200 --> 00:09:13,760
Some new programmers might confuse this with equate initialization.

127
00:09:14,970 --> 00:09:15,560
Here.

128
00:09:15,570 --> 00:09:19,530
So this this double equal.

129
00:09:19,740 --> 00:09:23,970
Double equal signs asks the Or.

130
00:09:27,830 --> 00:09:30,200
Here asks this.

131
00:09:32,250 --> 00:09:35,130
I get this text here, this ask this.

132
00:09:35,130 --> 00:09:39,960
So is the value of car.

133
00:09:40,960 --> 00:09:44,040
Equal to BMW.

134
00:09:45,140 --> 00:09:47,030
So here our.

135
00:09:49,130 --> 00:09:51,650
W equate equality.

136
00:09:51,860 --> 00:10:00,920
W equal sign asks whether value of this value of a car or a car in this case in is variable, right?

137
00:10:01,130 --> 00:10:10,730
Because we use this car as a variable name and here is the value of car equal to BMW.

138
00:10:10,730 --> 00:10:12,170
In this case it's equal.

139
00:10:12,170 --> 00:10:14,480
So it will return.

140
00:10:14,480 --> 00:10:15,230
True.
