WEBVTT

1
00:00.000 --> 00:03.960
Now that we know how to assign variables, let's talk a little bit more about

2
00:03.960 --> 00:04.960
the data types

3
00:04.960 --> 00:05.960
that we are using.

4
00:05.960 --> 00:09.430
So quite simply, with respect to Python, there are many different data types

5
00:09.430 --> 00:10.000
that you can

6
00:10.000 --> 00:12.600
utilize in this particular video though.

7
00:12.600 --> 00:16.760
What I want to focus in on is the string data type as well as the integer.

8
00:16.760 --> 00:18.600
So let's first begin with this one here.

9
00:18.600 --> 00:19.920
This sounds pretty strange.

10
00:19.920 --> 00:21.160
What an earth is it.

11
00:21.160 --> 00:24.840
Well, the good news is that we've all ready to deal with it.

12
00:24.840 --> 00:28.160
See for example, this right here, this happens to be a string.

13
00:28.160 --> 00:32.500
Now really in your mind, just conceptualize a string as a sequence of
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:28.160 --> 00:32.500
Now really in your mind, just conceptualize a string as a sequence of

14
00:32.500 --> 00:33.440
characters.

15
00:33.440 --> 00:35.120
It's basically used as the word text data.

16
00:35.120 --> 00:38.040
Now this text data can also include things like numbers.

17
00:38.040 --> 00:43.140
Say for example, if I wanted to add in the value of John 2001 at example.com as

18
00:43.140 --> 00:44.000
an email

19
00:44.000 --> 00:48.160
in the current context, this is all just one sequence of characters.

20
00:48.160 --> 00:52.140
So realistically, when we want our variable value to be a word or to be a

21
00:52.140 --> 00:53.040
sentence, that

22
00:53.040 --> 00:57.650
type of thing, the type of value we're going to be using is a string value

23
00:57.650 --> 00:58.080
versus

24
00:58.080 --> 01:03.430
if we want to utilize numerical values, then we would use something known as an
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

24
00:58.080 --> 01:03.430
if we want to utilize numerical values, then we would use something known as an

25
01:03.430 --> 01:04.320
integer.

26
01:04.320 --> 01:06.920
Now why is this actually important?

27
01:06.920 --> 01:07.920
Let me just show you why.

28
01:07.920 --> 01:08.920
Okay.

29
01:08.920 --> 01:09.920
That's a pretty variable here.

30
01:09.920 --> 01:10.920
Let's just say name is equal to John.

31
01:10.920 --> 01:11.920
Okay.

32
01:11.920 --> 01:12.920
Now watch this.

33
01:12.920 --> 01:15.640
If I just print out name right here, save this.

34
01:15.640 --> 01:18.800
If I try to run the example as it's down right here, look at this right there.

35
01:18.800 --> 01:23.240
It says we have a name error and the name John is not defined.

36
01:23.240 --> 01:25.600
So what exactly is going on here?

37
01:25.600 --> 01:29.260
Well, because this is going to be an order that sequence of characters, IAA

38
01:29.260 --> 01:30.640
string value,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

38
01:29.260 --> 01:30.640
string value,

39
01:30.640 --> 01:34.300
the way we actually assign this is we make sure that the value is within

40
01:34.300 --> 01:35.440
quotation marks.

41
01:35.440 --> 01:38.080
Watch what happens when I put the quotation marks.

42
01:38.080 --> 01:39.080
See this?

43
01:39.080 --> 01:40.080
This actually goes away.

44
01:40.080 --> 01:41.080
They're a little warning sign.

45
01:41.080 --> 01:45.520
And if I just rerun the script, suddenly we actually print out the value.

46
01:45.520 --> 01:49.510
So what this actually means is that the use of the quotation marks is actually

47
01:49.510 --> 01:49.880
very,

48
01:49.880 --> 01:50.880
very important.

49
01:50.880 --> 01:52.520
Let me just highlight to you why.

50
01:52.520 --> 01:56.200
So that's a pretty variable called first number.

51
01:56.200 --> 02:01.330
Now if I give it the number, let's say 10 and I use the quotation marks here,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

51
01:56.200 --> 02:01.330
Now if I give it the number, let's say 10 and I use the quotation marks here,

52
02:01.330 --> 02:01.840
we're

53
02:01.840 --> 02:05.640
actually not using in numerical value, we are really using a string.

54
02:05.640 --> 02:10.880
So then if I say the second number is equal to and again, I add in with

55
02:10.880 --> 02:11.720
quotation marks

56
02:11.720 --> 02:16.550
the number five and I then say the total number is equal to and I take the

57
02:16.550 --> 02:17.480
first number

58
02:17.480 --> 02:21.940
and I add it to the second number and then I try to print the value of the

59
02:21.940 --> 02:22.960
total number.

60
02:22.960 --> 02:24.880
What do you think the value is going to be?

61
02:24.880 --> 02:28.680
Now mathematically, if you look at this, you would say, well, 10 plus five is

62
02:28.680 --> 02:29.520
equal to 15

63
02:29.520 --> 02:32.960
and we give this particular value to the variable total number.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

63
02:29.520 --> 02:32.960
and we give this particular value to the variable total number.

64
02:32.960 --> 02:35.480
So we should be printing out the value 15.

65
02:35.480 --> 02:37.960
This is not what we're going to see though.

66
02:37.960 --> 02:38.960
Check this out.

67
02:38.960 --> 02:41.680
If I just run this, look at what we actually get here.

68
02:41.680 --> 02:46.260
Because we have defined each data type as a string value, they are being

69
02:46.260 --> 02:47.400
treated as ordered

70
02:47.400 --> 02:51.040
sequences of characters, not as numerical values.

71
02:51.040 --> 02:54.690
So realistically, all that is happening here is we've taken the first number,

72
02:54.690 --> 02:55.240
which is

73
02:55.240 --> 02:59.390
one zero and then we've added on the second number, which is a five and we've

74
02:59.390 --> 03:00.240
given the total
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

74
02:59.390 --> 03:00.240
given the total

75
03:00.240 --> 03:02.640
value of one or five.

76
03:02.640 --> 03:06.790
So obviously this is a little bit of a problem, very much so though, when you

77
03:06.790 --> 03:07.520
want to be dealing

78
03:07.520 --> 03:11.590
with these numerical values that actually have some type of mathematical

79
03:11.590 --> 03:12.320
context.

80
03:12.320 --> 03:15.720
Now really quite simple to define an integer.

81
03:15.720 --> 03:20.060
All we do is we actually use a number of value in the numerical value, I say,

82
03:20.060 --> 03:20.480
and we do

83
03:20.480 --> 03:23.360
not actually use the quotations.

84
03:23.360 --> 03:26.310
Now just to be clear here, if I only did this once, watch what happens, I'm

85
03:26.310 --> 03:27.000
trying to add

86
03:27.000 --> 03:29.120
an integer to a string.

87
03:29.120 --> 03:32.160
If I run this again, we're going to get a problem.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
03:29.120 --> 03:32.160
If I run this again, we're going to get a problem.

88
03:32.160 --> 03:33.160
It's going to give us a type error.

89
03:33.160 --> 03:38.400
It's going to say we cannot actually add an integer and a string together.

90
03:38.400 --> 03:39.760
So check this out.

91
03:39.760 --> 03:44.480
If I now specify the value here, I'm now using integers.

92
03:44.480 --> 03:50.240
If I just are up and rerun this, now we're getting that mathematical operation.

93
03:50.240 --> 03:54.400
Now let me just show you one very good function that you can use with respect

94
03:54.400 --> 03:55.100
to your data

95
03:55.100 --> 03:56.100
types.

96
03:56.100 --> 03:59.920
We actually have a type function that will tell you the type that is used

97
03:59.920 --> 04:00.840
within a particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

97
03:59.920 --> 04:00.840
within a particular

98
04:00.840 --> 04:01.840
variable.

99
04:01.840 --> 04:05.700
So I just happen to print out the type here and I run the script, but actually

100
04:05.700 --> 04:06.200
seeing

101
04:06.200 --> 04:11.230
we are returning an integer, whereas if I put both of these values within quot

102
04:11.230 --> 04:12.040
ations right

103
04:12.040 --> 04:15.960
here, again, we're going to be concatenating strings together.

104
04:15.960 --> 04:19.320
If I run it now, we can see we're returning a string value.

105
04:19.320 --> 04:22.760
So this is a very good way to eyeball the information that you're using.

106
04:22.760 --> 04:26.360
Now these are just two of the data types that we can be using.

107
04:26.360 --> 04:29.760
And one last thing to note here, remember I said how Python was dynamic.

108
04:29.760 --> 04:34.560
We can just assign variable values without defining the data type.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

108
04:29.760 --> 04:34.560
We can just assign variable values without defining the data type.

109
04:34.560 --> 04:35.560
Watch this.

110
04:35.560 --> 04:37.680
Say for example, I changed this to five.

111
04:37.680 --> 04:41.580
We know right here, if I just try to print this out as it is, you're doing

112
04:41.580 --> 04:42.800
these parentheses,

113
04:42.800 --> 04:43.880
let's just save this.

114
04:43.880 --> 04:47.080
We know as it stands, this is going to give us an error as such.

115
04:47.080 --> 04:51.530
Now we know what I can do is take my variable here and just dynamically reass

116
04:51.530 --> 04:52.320
ign it so I can

117
04:52.320 --> 04:54.000
just reassign it right there.

118
04:54.000 --> 04:58.400
So the first time it was defined, it was a string value stored as this

119
04:58.400 --> 04:59.680
particular variable

120
04:59.680 --> 05:03.520
first number, but then we just modify it to completely different type.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

120
04:59.680 --> 05:03.520
first number, but then we just modify it to completely different type.

121
05:03.520 --> 05:08.100
So we're not just updating the value of the same type, but actually changing

122
05:08.100 --> 05:09.600
the type entirely.

123
05:09.600 --> 05:13.400
Watch what happens now because we are able to dynamically update this.

124
05:13.400 --> 05:14.400
And I run the script.

125
05:14.400 --> 05:17.000
Suddenly, everything is working quite just fine.

126
05:17.000 --> 05:20.760
So the key take home points right here to note are the data types that we

127
05:20.760 --> 05:21.840
assign to particular

128
05:21.840 --> 05:26.560
variables actually can have a profound effect on the execution of our program.

129
05:26.560 --> 05:31.010
And as we can see here, Python, being a dynamic language does not require us to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

129
05:26.560 --> 05:31.010
And as we can see here, Python, being a dynamic language does not require us to

130
05:31.010 --> 05:32.800
manually specify

131
05:32.800 --> 05:36.400
which data type we want to be using when creating our variables.

132
05:36.400 --> 05:38.760
They can just be modified as we need.

133
05:38.760 --> 05:41.760
And Python will just accept those values dynamically.

134
05:41.760 --> 05:45.310
So now we know about strings and integers, the next data type that I want to

135
05:45.310 --> 05:46.160
talk to about

136
05:46.160 --> 05:48.200
are lists and dictionaries.
