1
00:00:00,070 --> 00:00:05,070
Yesterday you saw that we could use the Len function to get the number of

2
00:00:05,410 --> 00:00:09,640
characters in a string. So for example, when I write Len,

3
00:00:09,670 --> 00:00:12,580
hello and I print this out,

4
00:00:13,360 --> 00:00:17,500
we end up with 5. There's 5 characters in the string hello.

5
00:00:18,280 --> 00:00:19,570
Now here's a question.

6
00:00:20,170 --> 00:00:25,170
What happens if instead of counting the number of characters in a string,

7
00:00:26,200 --> 00:00:31,200
what if I put in a number instead and I wanted to know how many digits are in

8
00:00:31,780 --> 00:00:35,800
this number? Now if I go ahead and run this code,

9
00:00:35,980 --> 00:00:37,810
you'll see that it actually crashes.

10
00:00:38,260 --> 00:00:43,260
I get a whole bunch of red text and it tells me that there is a type error and

11
00:00:44,380 --> 00:00:49,150
something about the type int. So what is all of this about?

12
00:00:49,840 --> 00:00:54,370
Well, in order to understand it, we first have to learn about data types.

13
00:00:55,120 --> 00:00:59,680
Now on day 1, we already explored this data type called strings.

14
00:01:00,100 --> 00:01:03,760
Now you're probably not going to be surprised to learn that there's a whole lot

15
00:01:03,760 --> 00:01:05,770
more other data types out there.

16
00:01:06,250 --> 00:01:11,140
And today we're going to explore some of the most important and some of the most

17
00:01:11,140 --> 00:01:15,820
basic data types such as strings, integers, float, and booleans.

18
00:01:16,270 --> 00:01:18,580
And we'll explore each of these in detail.

19
00:01:19,300 --> 00:01:24,300
So go ahead and get hold of the day 2 start coding sandbox and go ahead and

20
00:01:25,540 --> 00:01:29,050
fork your own copy of it. Now once you've done that,

21
00:01:29,110 --> 00:01:31,360
let's take a look at some of the data types.

22
00:01:31,480 --> 00:01:34,240
So we already learned about strings, right?

23
00:01:34,360 --> 00:01:38,650
And we know that this is just a string of characters.

24
00:01:38,980 --> 00:01:43,980
So the word hello is comprised of these five characters strung together.

25
00:01:44,320 --> 00:01:47,680
And we always know that strings, when we create them,

26
00:01:47,890 --> 00:01:49,960
we have to create them with these double quotes around.

27
00:01:50,440 --> 00:01:53,110
Now because this is a string of characters,

28
00:01:53,470 --> 00:01:58,390
we can actually pull out each character individually. So we could, for example,

29
00:01:58,570 --> 00:02:02,890
instead of just writing hello, we can add some square brackets.

30
00:02:03,280 --> 00:02:06,220
So take a look on your keyboard and see where those are.

31
00:02:06,730 --> 00:02:11,730
And inside the square brackets, we can put the index or the position of the

32
00:02:12,730 --> 00:02:15,010
character that we want. So, for example,

33
00:02:15,010 --> 00:02:19,390
if I wanted to have the first character out of this word hello,

34
00:02:19,420 --> 00:02:21,310
I would put zero right here.

35
00:02:21,910 --> 00:02:26,350
And if I go ahead and print what this actually will give me,

36
00:02:26,800 --> 00:02:31,800
you'll see that you get capital H because that is the first character of this

37
00:02:32,890 --> 00:02:33,723
string.

38
00:02:33,970 --> 00:02:38,140
And it's really important to remember that programmers always start counting

39
00:02:38,140 --> 00:02:42,190
from zero because we work with binary, zeros and ones.

40
00:02:42,460 --> 00:02:46,810
So whenever you want to get hold of the first character or the first of

41
00:02:46,810 --> 00:02:49,480
anything, it always is at zero.

42
00:02:50,080 --> 00:02:54,910
So this method of pulling out a particular element from a string is called sub-

43
00:02:54,910 --> 00:02:58,960
scripting. And the number in between the square brackets determines

44
00:02:59,770 --> 00:03:01,270
which character you're going to pull out,

45
00:03:01,600 --> 00:03:06,600
and it just goes up from zero to one to two and so on and so forth.

46
00:03:07,240 --> 00:03:10,240
So whenever you get a result that's just off by one,

47
00:03:10,480 --> 00:03:15,480
then remember to check whether if you've started counting from zero or if you

48
00:03:15,580 --> 00:03:17,140
started counting from one.

49
00:03:18,040 --> 00:03:22,360
Now you can of course extend this and get hold of the last character.

50
00:03:22,570 --> 00:03:27,100
So pause the video and see if you can change the code so that 'o' gets printed

51
00:03:27,100 --> 00:03:29,440
out here. All right,

52
00:03:29,440 --> 00:03:33,760
so this is a simple as simply counting from zero, one, two, three,

53
00:03:33,940 --> 00:03:38,020
four. So if we change this to four and we run our code,

54
00:03:38,320 --> 00:03:41,080
then you'll see that 'o' gets printed instead of the H.

55
00:03:41,620 --> 00:03:44,980
So by using these square brackets and putting a number inside,

56
00:03:45,280 --> 00:03:50,280
we're able to dissect our string and pull out individual characters as and when

57
00:03:50,980 --> 00:03:51,813
we need it.

58
00:03:52,120 --> 00:03:55,840
And this will come in really handy in a lot of the programs that you'll write in

59
00:03:55,840 --> 00:03:56,673
the future.

60
00:03:57,220 --> 00:04:02,140
Now it's important to remember though that just because I can write a number

61
00:04:02,170 --> 00:04:03,520
like "123",

62
00:04:04,180 --> 00:04:07,660
as long as it's kept inside these double quotes,

63
00:04:07,990 --> 00:04:11,440
then this is not treated as a number by the computer.

64
00:04:11,440 --> 00:04:16,420
It's treated just as any other piece of text. You can't, for example, say,

65
00:04:16,480 --> 00:04:21,040
um, what is "123" + "345".

66
00:04:21,490 --> 00:04:25,720
If I try to print this, what do you think will happen?

67
00:04:26,260 --> 00:04:29,110
Do you think it will give me 123 + 345

68
00:04:29,110 --> 00:04:30,820
in the traditional sense,

69
00:04:30,820 --> 00:04:35,410
like calculating it or do you think it'll do something else? All right,

70
00:04:35,470 --> 00:04:39,970
let's hit run and we get 123345.

71
00:04:40,240 --> 00:04:44,140
So it's basically just concatenated these two strings together,

72
00:04:44,380 --> 00:04:49,330
just as we have done with other strings like hello and world, right?

73
00:04:50,170 --> 00:04:54,700
Because it sees the datatype of these two pieces of data as strings.

74
00:04:55,060 --> 00:04:56,650
When we use the plus sign,

75
00:04:56,830 --> 00:05:01,450
it will actually just concatenate these two things instead of doing a

76
00:05:01,450 --> 00:05:05,140
mathematical operation. Now if we want to do that,

77
00:05:05,200 --> 00:05:10,120
then we actually have to declare our number as a number data type.

78
00:05:10,450 --> 00:05:13,780
So one of the most common that you'll see is called an integer.

79
00:05:14,200 --> 00:05:18,250
So this is programming lingo for just whole numbers, numbers

80
00:05:18,250 --> 00:05:20,290
without any decimal places.

81
00:05:20,860 --> 00:05:25,000
And in order to create an integer or declare an integer data type,

82
00:05:25,300 --> 00:05:29,560
all you have to do is just write the number without anything else.

83
00:05:30,220 --> 00:05:34,300
So now if I just write the numbers, 123 + 345

84
00:05:34,300 --> 00:05:37,150
and then I go ahead and print this,

85
00:05:37,720 --> 00:05:40,720
then you'll see that we actually get 468.

86
00:05:40,720 --> 00:05:45,550
So it's actually being calculated because I've got actual numbers instead of

87
00:05:45,670 --> 00:05:46,540
strings.

88
00:05:47,290 --> 00:05:50,800
Just as we have some useful things that we can do with strings.

89
00:05:51,130 --> 00:05:53,650
There's some really handy things that you can do with integers.

90
00:05:54,400 --> 00:05:57,890
Commonly when we write large numbers,

91
00:05:58,100 --> 00:06:02,600
at least in the UK or in the US, we'd like to put commas in between the

92
00:06:02,600 --> 00:06:03,380
thousands.

93
00:06:03,380 --> 00:06:08,380
So when we think of large numbers with these commas in between to split it into

94
00:06:08,390 --> 00:06:11,720
an easier to understand number. In Python,

95
00:06:11,750 --> 00:06:16,750
we can replace those commas simply with underscores and it will be interpreted

96
00:06:16,820 --> 00:06:20,330
by the computer as if you had written this.

97
00:06:20,630 --> 00:06:23,960
So the computer actually removes those underscores and ignores it.

98
00:06:24,440 --> 00:06:29,120
The benefit is just for us humans to be able to visualize it more easily.

99
00:06:29,780 --> 00:06:32,060
So I mentioned that all whole numbers

100
00:06:32,060 --> 00:06:36,170
no matter if they're positive or negative, are called integers in programming.

101
00:06:36,770 --> 00:06:40,250
So what do you call it when you actually have decimal places? Well,

102
00:06:40,280 --> 00:06:45,280
they are called a float and this is short for a floating-point number.

103
00:06:45,680 --> 00:06:49,940
So for example, if you had um, the numbers of PI,

104
00:06:49,970 --> 00:06:51,770
you have 3.14159

105
00:06:51,830 --> 00:06:56,830
and this, because it has a decimal place, is now a float data type.

106
00:06:58,580 --> 00:07:03,580
So if you think of the decimal point as being able to float around the number

107
00:07:04,070 --> 00:07:06,020
because it could occur at any point,

108
00:07:06,290 --> 00:07:08,900
then you've got yourself a floating point number.

109
00:07:10,100 --> 00:07:14,090
Now the final data type is something called a boolean.

110
00:07:14,960 --> 00:07:18,740
And this is very simple. It only has two possible values,

111
00:07:19,100 --> 00:07:20,990
true or false.

112
00:07:21,350 --> 00:07:26,350
Now note how these values always begin with a capital T or capital F and they

113
00:07:27,410 --> 00:07:30,290
don't have any quotation marks around them or anything.

114
00:07:30,560 --> 00:07:35,510
So this is actually a data type which is going to be used a lot in your programs

115
00:07:35,780 --> 00:07:37,280
to test if something is true,

116
00:07:37,280 --> 00:07:41,300
if something is false and for your program to respond accordingly.

117
00:07:41,690 --> 00:07:44,390
So we're going to be using this a lot more in the future.

118
00:07:44,870 --> 00:07:49,250
Now that you've seen a lot of the basic data types, strings, integers, floats,

119
00:07:49,250 --> 00:07:50,083
and boolean,

120
00:07:50,270 --> 00:07:54,620
I want you to head over to the next lesson where I've got a quiz for you to see

121
00:07:54,620 --> 00:07:58,640
if you've made this knowledge your own. So head over to the quiz and give it a go.

