1
00:00:00,750 --> 00:00:02,010
When working with strings.

2
00:00:02,040 --> 00:00:05,160
Another common task is to remove a prefix.

3
00:00:05,160 --> 00:00:15,440
Consider a URL with the common prefix https and we want to remove this prefix so we can focus on just

4
00:00:15,450 --> 00:00:21,270
a part of the URL that the users need to enter into an address bar.

5
00:00:21,300 --> 00:00:22,920
Here's how you do that.

6
00:00:22,950 --> 00:00:26,940
Firstly, we will enter the auxiliary URL.

7
00:00:27,300 --> 00:00:31,800
URL and here we will enter.

8
00:00:32,680 --> 00:00:44,380
Http oxley.com and is actually Udemy URL but in this case Udemy url will be https.

9
00:00:44,410 --> 00:00:44,980
Right.

10
00:00:45,010 --> 00:00:46,780
It will have different.

11
00:00:47,710 --> 00:00:48,280
Perfect.

12
00:00:50,180 --> 00:00:53,300
And here we will udemy.com.

13
00:00:54,050 --> 00:00:55,010
Now.

14
00:00:57,810 --> 00:00:59,010
Let's do this.

15
00:00:59,040 --> 00:00:59,640
Oxalate.

16
00:00:59,640 --> 00:01:02,090
That oxalate equals oxalate.

17
00:01:02,760 --> 00:01:07,590
Remove prefix http http.

18
00:01:08,880 --> 00:01:09,450
Here.

19
00:01:09,450 --> 00:01:13,710
And for Udemy we will use different https, right?

20
00:01:15,620 --> 00:01:18,080
What Udemy URL.

21
00:01:19,210 --> 00:01:21,730
Udemy url dot remove prefix.

22
00:01:21,790 --> 00:01:23,320
Http here.

23
00:01:23,350 --> 00:01:33,280
So if we do this and let's print this after that print url and print Udemy url.

24
00:01:33,280 --> 00:01:34,000
That's it.

25
00:01:34,860 --> 00:01:36,540
Now let's run this.

26
00:01:36,960 --> 00:01:38,190
And as you can see here.

27
00:01:38,190 --> 00:01:47,940
Yes, excellent Comet changed, but all udemy.com is left unchanged because we need to add s here to

28
00:01:47,940 --> 00:01:49,610
completely fix this.

29
00:01:49,620 --> 00:01:52,920
And here, as you can see here, com is changed.

30
00:01:52,920 --> 00:02:02,880
So you enter the name of the variable followed by a dot and then the method remove prefix.

31
00:02:03,210 --> 00:02:09,210
So inside the parentheses enter the prefix you want to remove from the original string.

32
00:02:10,380 --> 00:02:16,320
So like the methods for removing whitespace remove prefix leaves the original string unchanged.

33
00:02:16,350 --> 00:02:24,510
So if you want to keep the new value with the prefix removed, either reassign to the original variable

34
00:02:24,690 --> 00:02:28,230
like I did here or assign it to a new variable.

35
00:02:28,710 --> 00:02:34,920
So when you see a URL in an address bar, uh, the http.

36
00:02:36,010 --> 00:02:38,290
This part isn't shown.

37
00:02:38,320 --> 00:02:43,660
The browser is probably using a method like remove prefix.

38
00:02:44,050 --> 00:02:45,460
Behind the scenes.

39
00:02:46,490 --> 00:02:53,720
Let's actually now learn about how to avoid syntax errors with strings.

40
00:02:53,780 --> 00:03:01,400
So one kind of error that you might see with some regularity is a syntax error.

41
00:03:01,430 --> 00:03:09,260
A syntax error occurs when Python doesn't recognize a section of your program as valid python code.

42
00:03:09,290 --> 00:03:15,890
For example, if you use apostrophe within a single quotes, you will produce error.

43
00:03:15,920 --> 00:03:22,700
This happens because Python interprets everything between the first single quote and the apostrophe

44
00:03:22,730 --> 00:03:23,900
as a string.

45
00:03:23,930 --> 00:03:27,590
So it then tries to interpret the rest of.

46
00:03:29,620 --> 00:03:34,810
Uh, interpret the rest of the text as a python code, which causes errors.

47
00:03:34,810 --> 00:03:39,700
So here's how you use the single and the double quotes correctly.

48
00:03:39,850 --> 00:03:43,000
So now we will enter this here.

49
00:03:43,120 --> 00:03:46,210
Now I will share this quotes with you.

50
00:03:46,210 --> 00:03:47,050
So.

51
00:03:49,060 --> 00:03:51,070
Example one.

52
00:03:52,790 --> 00:03:53,270
Here.

53
00:03:55,060 --> 00:03:55,990
Now.

54
00:04:13,430 --> 00:04:14,360
I'll do this.

55
00:04:14,640 --> 00:04:14,900
That's.

56
00:04:16,630 --> 00:04:17,830
And now.

57
00:04:19,140 --> 00:04:19,560
Um.

58
00:04:25,970 --> 00:04:27,860
Now, let's actually write this here.

59
00:04:28,340 --> 00:04:33,110
As we said, the message here one.

60
00:04:33,950 --> 00:04:40,200
Oh, one of the one of the titans of.

61
00:04:41,600 --> 00:04:46,580
Fighters strength is its diverse.

62
00:04:53,700 --> 00:04:54,900
Yeah, it's.

63
00:04:55,080 --> 00:04:56,580
Is it?

64
00:04:58,040 --> 00:04:59,270
Diverse.

65
00:05:01,400 --> 00:05:02,300
Community.

66
00:05:03,240 --> 00:05:03,900
Here.

67
00:05:03,900 --> 00:05:05,550
We will print this message.

68
00:05:06,060 --> 00:05:06,810
Message?

69
00:05:08,610 --> 00:05:09,990
I was, actually.

70
00:05:13,320 --> 00:05:16,710
Now we will create a text file here and.

71
00:05:19,030 --> 00:05:19,690
Here.

72
00:05:19,690 --> 00:05:30,160
The first rope appears inside a set of double quotes so the python interpreter has no trouble executing

73
00:05:30,160 --> 00:05:31,720
and running this command.

74
00:05:31,720 --> 00:05:33,760
So it's okay for now.

75
00:05:34,300 --> 00:05:37,480
However, if you use single quotes.

76
00:05:38,330 --> 00:05:43,760
Python cannot identify where the string should end.

77
00:05:44,060 --> 00:05:50,300
So here we will get an error and this code will not compile because as you can see, we have an error

78
00:05:50,300 --> 00:05:51,650
in line one message.

79
00:05:51,810 --> 00:05:56,020
The python's strength is its diverse community.

80
00:05:56,030 --> 00:05:57,830
Invalid syntax.

81
00:05:59,790 --> 00:06:03,330
And here you will see this error something.

82
00:06:03,540 --> 00:06:11,130
And in the output you can see that error occurs right after the final single quote here.

83
00:06:13,690 --> 00:06:20,740
And this syntax error indicates that the interpreter doesn't recognize something in the code as valid

84
00:06:20,770 --> 00:06:21,250
python code.

85
00:06:21,280 --> 00:06:21,660
Right.

86
00:06:21,670 --> 00:06:28,780
And it thinks the problem might be a string that's not quoted correctly and the errors can.

87
00:06:29,680 --> 00:06:34,590
From a variety of sources, and I will point out some common ones as they arise.

88
00:06:34,600 --> 00:06:40,060
So you might see syntax errors often as you learn to write proper python code.

89
00:06:40,420 --> 00:06:45,160
So syntax errors are also the least specific kinds of errors.

90
00:06:45,160 --> 00:06:51,130
So they can be difficult and frustrating to identify and correct.

91
00:06:51,130 --> 00:06:59,140
So if you get stuck on a particular step or an error, you can ask me and I will answer them immediately.
