1
00:00:00,009 --> 00:00:00,850
Welcome back.

2
00:00:00,860 --> 00:00:04,909
So let's continue talking about the different types of methods or functions

3
00:00:05,250 --> 00:00:09,229
that we typically apply on strings and one very common, one, in fact,

4
00:00:09,239 --> 00:00:10,670
two very common ones rather

5
00:00:10,970 --> 00:00:17,670
would be the functions for converting text either to upper case or lower case. So

6
00:00:18,370 --> 00:00:22,790
in my example, over here, I have my variable text equal to cybersecurity.

7
00:00:22,799 --> 00:00:25,229
If I wanted to convert everything to uppercase,

8
00:00:25,559 --> 00:00:28,920
I would simply say text and now dot

9
00:00:29,219 --> 00:00:29,510
upper

10
00:00:30,180 --> 00:00:31,549
open up new brackets.

11
00:00:31,870 --> 00:00:32,830
And there it is.

12
00:00:33,209 --> 00:00:36,790
And if I wanted to convert everything to lowercase, I'll do the exact opposite,

13
00:00:36,799 --> 00:00:39,290
this will be print text dot lower

14
00:00:40,889 --> 00:00:41,400
dot lower,

15
00:00:42,439 --> 00:00:46,349
open up new brackets and there it is. So if I run the program right now,

16
00:00:46,630 --> 00:00:49,229
you can see we have cybersecurity in capital letters

17
00:00:49,360 --> 00:00:52,299
and then cybersecurity in lower case letter.

18
00:00:52,310 --> 00:00:56,150
So these are two new functions you should be aware of dot Oper

19
00:00:56,400 --> 00:00:56,779
dot lower,

20
00:00:57,599 --> 00:01:02,950
but there is also the function for trimming white space.

21
00:01:02,959 --> 00:01:07,610
So say for example, I have my password variable in here, I've got space

22
00:01:07,989 --> 00:01:11,889
and my actual password is swordfish. And then let me add some more space

23
00:01:12,239 --> 00:01:16,500
if I wanted to trim all the unnecessary white space in here.

24
00:01:16,779 --> 00:01:20,970
All I would do is I would say prints brackets and then password.

25
00:01:21,610 --> 00:01:24,239
And now strip, once again

26
00:01:24,379 --> 00:01:26,559
the strip function, we can also use it

27
00:01:26,660 --> 00:01:29,160
to remove any unnecessary white space,

28
00:01:29,349 --> 00:01:33,949
run the program. And there you go, swordfish without the empty space.

29
00:01:34,470 --> 00:01:36,190
But we can also

30
00:01:36,400 --> 00:01:39,250
replace characters

31
00:01:39,760 --> 00:01:41,459
in our strings.

32
00:01:41,940 --> 00:01:45,029
Say, for example, let me just give you an example in here.

33
00:01:45,690 --> 00:01:48,830
Let's say I've got my message being equal to

34
00:01:49,580 --> 00:01:53,959
and let's say, ok, user password.

35
00:01:54,779 --> 00:01:55,370
Ok.

36
00:01:55,760 --> 00:01:59,879
And let's say the password right now is password 123.

37
00:02:00,610 --> 00:02:01,230
Ok,

38
00:02:01,750 --> 00:02:03,169
just as an example, right?

39
00:02:03,459 --> 00:02:06,730
But then we wanted to print something that will say, ok,

40
00:02:06,739 --> 00:02:09,470
use a password and then redact it.

41
00:02:09,970 --> 00:02:12,910
Ok? We don't want to display the actual password itself.

42
00:02:13,279 --> 00:02:16,289
It's similar to what we did in the previous lesson

43
00:02:16,300 --> 00:02:20,039
where we use the asterisk symbol to replace the characters.

44
00:02:20,470 --> 00:02:24,470
It's related but slightly different. So let me show you what I'm talking about. Ok.

45
00:02:24,479 --> 00:02:25,910
So I'm gonna come over here right now

46
00:02:26,429 --> 00:02:27,429
and I'm gonna say

47
00:02:28,100 --> 00:02:31,899
let's create a new variable, let's say secure

48
00:02:32,800 --> 00:02:35,100
underscore message, ok,

49
00:02:35,919 --> 00:02:41,970
will be equal to now message dot And now a new function called replace.

50
00:02:42,320 --> 00:02:42,919
Ok,

51
00:02:43,460 --> 00:02:49,399
I want to replace the actual password with something else. So

52
00:02:49,520 --> 00:02:51,419
inside of my brackets,

53
00:02:51,630 --> 00:02:54,970
I am now going to put the actual password I want to replace, which is password.

54
00:02:55,630 --> 00:02:57,509
Uh 123

55
00:02:57,979 --> 00:03:03,750
comma and now the actual letters or characters or string

56
00:03:04,070 --> 00:03:09,369
I want to replace it with, in this case, right now, I'm gonna open up my brackets

57
00:03:09,820 --> 00:03:12,460
and in capital letters I can say redacted

58
00:03:12,929 --> 00:03:15,949
just as an example. Ok. So now all I need to do

59
00:03:16,130 --> 00:03:20,770
is to simply print in brackets, secure underscore message.

60
00:03:21,369 --> 00:03:23,399
And now if I run my program,

61
00:03:23,610 --> 00:03:27,190
there you go, use a password reducted.

62
00:03:27,500 --> 00:03:31,210
So you can use the replace function to simply replace

63
00:03:31,350 --> 00:03:33,300
any particular part of your string

64
00:03:33,460 --> 00:03:36,990
with something else. And this is how you will do it

65
00:03:38,059 --> 00:03:43,369
to round up. Let me show you one more thing and this is finding substrings,

66
00:03:43,899 --> 00:03:45,520
say, for example,

67
00:03:46,270 --> 00:03:53,750
we have a variable called email and it's equal to, let's say admin at lab cyber.com.

68
00:03:54,320 --> 00:03:58,880
I'm pretty sure of course, you must have encountered this so many times before where

69
00:03:59,100 --> 00:04:01,929
maybe you're trying to create a new account on the website

70
00:04:02,259 --> 00:04:05,289
and they will ask you to provide an email address

71
00:04:05,539 --> 00:04:08,490
if you type in something bogus. For example,

72
00:04:08,830 --> 00:04:11,000
the system will be able to detect that, hey,

73
00:04:11,009 --> 00:04:14,449
this isn't a valid email address and that's because

74
00:04:14,789 --> 00:04:21,529
it could check to see if the at symbol was included in your input.

75
00:04:21,829 --> 00:04:25,019
So if the at symbol isn't there, then obviously it knows, OK,

76
00:04:25,029 --> 00:04:28,350
whatever this person typed in cannot be an email address.

77
00:04:28,929 --> 00:04:31,799
Let me show you how we can write a very simple program

78
00:04:31,809 --> 00:04:37,239
to check to see if the at symbol is in the string.

79
00:04:37,489 --> 00:04:38,720
So from here,

80
00:04:39,630 --> 00:04:44,500
I have my email it calls admin at labs.com. Let's check to see if the ad symbol is in it.

81
00:04:44,510 --> 00:04:47,329
Ok? I'm gonna say if, ok,

82
00:04:47,799 --> 00:04:52,019
if I know we haven't talked about this particular if statement yet, don't worry,

83
00:04:52,029 --> 00:04:54,500
we will cover it in a lot more detail in the next section.

84
00:04:54,510 --> 00:04:55,089
But for now

85
00:04:55,209 --> 00:04:57,890
just know that if is a statement

86
00:04:58,040 --> 00:05:00,690
that Python uses to check if something is true.

87
00:05:00,700 --> 00:05:04,489
So I'm gonna say if and our email and then

88
00:05:05,059 --> 00:05:05,970
dot

89
00:05:06,390 --> 00:05:07,760
find,

90
00:05:07,899 --> 00:05:13,970
this is the function that we can use to check to see if something exists in our string.

91
00:05:13,980 --> 00:05:15,769
So that's the find function.

92
00:05:16,130 --> 00:05:21,609
And now we have to specify what exactly are we looking for in brackets?

93
00:05:22,100 --> 00:05:24,010
And now encodes the

94
00:05:24,220 --> 00:05:25,529
at symbol.

95
00:05:25,869 --> 00:05:29,390
So I'm trying to check to see if the at symbol exists.

96
00:05:29,540 --> 00:05:33,410
And one way how we can verify that indeed,

97
00:05:33,690 --> 00:05:38,269
it does exist. It is in a string is by saying

98
00:05:38,619 --> 00:05:43,070
it is not equal to minus one

99
00:05:43,279 --> 00:05:45,230
and then we add our colon.

100
00:05:45,440 --> 00:05:51,309
So this not equals to minus one is a way of saying something does exist.

101
00:05:51,809 --> 00:05:53,070
OK? So

102
00:05:53,540 --> 00:05:54,470
right here

103
00:05:54,640 --> 00:05:57,510
we're saying if in the email,

104
00:05:57,799 --> 00:05:59,329
you found the at

105
00:05:59,470 --> 00:06:05,250
symbol and it's not equal to minus one. So this confirms that yes, indeed.

106
00:06:05,260 --> 00:06:09,489
The at symbol is in our string. So now we can do something

107
00:06:09,739 --> 00:06:13,089
we can say print and now in brackets, we can say

108
00:06:14,010 --> 00:06:16,869
a valid email format.

109
00:06:17,190 --> 00:06:19,190
So now if I run my program,

110
00:06:19,200 --> 00:06:23,290
there you go valid email format because the ad symbol was in fact found

111
00:06:23,399 --> 00:06:25,670
if I remove the ad symbol

112
00:06:26,140 --> 00:06:29,769
and now I run the program again, you can see nothing is printed out because

113
00:06:29,869 --> 00:06:32,049
the ad symbol is no longer there.

114
00:06:32,059 --> 00:06:39,029
It is not a valid email for mat, I go back, I add the ad symbol again. Iron

115
00:06:39,170 --> 00:06:41,579
and now you can see it's working again.

116
00:06:42,209 --> 00:06:48,959
So to give you a quick recap, first of all, we want to look for the add symbol in

117
00:06:49,230 --> 00:06:52,910
an email address provided to us. So we're gonna say if

118
00:06:53,299 --> 00:06:58,579
and then we're looking specifically for the add symbol. So if the add symbol

119
00:06:58,730 --> 00:07:04,970
is present and we check to see if it's present with the not equals to minus one. So

120
00:07:05,209 --> 00:07:07,869
if the add symbol is in fact present

121
00:07:08,130 --> 00:07:14,989
simpleprint, valid email format. So take note of the find function.

122
00:07:15,179 --> 00:07:18,269
So that's it for the video. Thank you for watching. I will see you in the next class.