String Methods in Python | Python Tutorial - Day #13

CodeWithHarry
10 Dec 202222:32

Summary

TLDRIn this engaging '100 Days Of Code' episode, the presenter dives into the world of Python 'String' methods, offering a fun and informative tutorial. The video explains string immutability and demonstrates various methods such as 'upper()', 'lower()', 'rstrip()', 'replace()', and 'split()', illustrating how they operate on strings to produce new ones. It also covers methods like 'capitalize()', 'center()', 'count()', 'endswith()', 'find()', 'index()', 'isalnum()', 'isalpha()', 'islower()', 'isprintable()', 'isspace()', 'istitle()', 'isupper()', 'startswith()', 'swapcase()', and 'title()'. The presenter emphasizes the practicality of these methods for tasks like blog writing and provides a hands-on approach using Replit. Additionally, the video shares insights into the presenter's recording setup, utilizing MacBook, iPhone's 'Continuity Camera', and OBS for high-quality video production.

Takeaways

  • ๐Ÿ“บ The '100 Days Of Code' series is likened to a Netflix series, generating excitement among viewers.
  • ๐Ÿ”ก The video focuses on 'String' methods, explaining how to manipulate strings in various ways, such as converting to uppercase or lowercase.
  • ๐Ÿ”‘ The concept of 'immutability' is introduced, emphasizing that strings in Python cannot be changed in-place but can be copied and modified.
  • ๐Ÿ”„ The 'upper()', 'lower()', and 'capitalize()' methods are discussed, showing how they alter the case of string characters.
  • ๐Ÿ“ The 'len()' function is mentioned for determining the length of a string.
  • ๐Ÿ’ฅ The 'replace()' method is explained, demonstrating how to substitute all occurrences of a substring within a string.
  • ๐Ÿ“‹ The 'split()' method is briefly introduced as a way to convert a string into a list based on spaces.
  • ๐Ÿ“ 'rstrip()' is highlighted for its role in removing trailing characters from a string.
  • ๐Ÿ” The 'count()', 'endswith()', and 'find()' methods are covered, explaining how to count occurrences, check for ending characters, and find the index of a substring.
  • ๐Ÿ“š Additional string methods like 'isalnum()', 'isalpha()', 'islower()', 'isprintable()', 'isspace()', 'istitle()', 'isupper()', 'startswith()', and 'swapcase()' are mentioned, each serving specific string validation or transformation purposes.

Q & A

  • What is the main topic discussed in the video?

    -The main topic discussed in the video is 'String' methods in Python, including various operations that can be performed on strings such as converting to uppercase or lowercase, finding the length, and other string manipulation techniques.

  • Why does the video mention the concept of immutability in the context of strings?

    -The concept of immutability is mentioned to explain that strings in Python cannot be changed in-place. Instead, string methods return a new string after performing the operation, which is an important aspect when working with strings in Python.

  • What is the purpose of the 'upper()' method in Python strings?

    -The 'upper()' method is used to convert all the characters in a string to uppercase letters, creating a new string with the changes.

  • How does the 'lower()' method differ from the 'upper()' method?

    -The 'lower()' method, unlike the 'upper()' method, converts all the characters in a string to lowercase letters, also creating a new string with the changes.

  • What does the 'rstrip' method do in Python strings?

    -The 'rstrip' method is used to remove any trailing whitespace or specified characters from the end of a string, leaving the rest of the string unchanged.

  • Can you explain the 'replace' method in Python strings?

    -The 'replace' method is used to replace all occurrences of a specified substring with another substring within a string, and it returns a new string with the replacements made.

  • What is the 'split' method used for in Python strings?

    -The 'split' method is used to split a string into a list of substrings based on a specified delimiter, such as a space or any other character. It's useful for breaking down strings into more manageable pieces.

  • What does the 'capitalize' method do, and in which programming language is it available?

    -The 'capitalize' method turns the first character of a string to uppercase and the rest to lowercase. It is available in Python, not JavaScript as mistakenly mentioned in the script.

  • How does the 'center' method work in Python strings?

    -The 'center' method aligns the string to the center, padding it with spaces or another specified character on both sides to a given width, effectively creating a centered string.

  • What is the 'count' method used for in Python strings?

    -The 'count' method is used to count the number of occurrences of a specified substring within a string and returns the count as an integer.

  • What does the 'endswith' method check in a Python string?

    -The 'endswith' method checks if a string ends with a specified character or substring and returns a Boolean value (True or False) based on whether the condition is met.

  • What is the difference between 'find' and 'index' methods in Python strings?

    -Both 'find' and 'index' methods search for the first occurrence of a specified substring within a string. The difference is that 'find' returns -1 if the substring is not found, while 'index' raises a ValueError exception if the substring is not found.

  • What does the 'isalnum' method check in a Python string?

    -The 'isalnum' method checks if all characters in a string are alphanumeric (consisting of A-Z, a-z, or 0-9) and returns True if so, otherwise it returns False.

  • How does the 'isspace' method determine the content of a Python string?

    -The 'isspace' method checks if a string contains only whitespace characters, such as spaces, tabs, or newlines, and returns True if it does, otherwise it returns False.

  • What is the purpose of the 'istitle' method in Python strings?

    -The 'istitle' method checks if the first character of each word in a string is capitalized and the rest are lowercase, which is typically used for checking the formatting of titles.

  • Can you describe the 'startswith' method in Python strings?

    -The 'startswith' method is used to check if a string starts with a specified character or substring and returns a Boolean value (True or False) based on whether the condition is met.

  • What does the 'swapcase' method do to a Python string?

    -The 'swapcase' method swaps the case of each character in a string, converting uppercase characters to lowercase and vice versa.

  • What is the 'title' method used for in Python strings?

    -The 'title' method is used to convert the first character of each word in a string to uppercase and the rest to lowercase, creating a title-cased version of the string.

  • How does the video creator record his videos, and what setup does he use?

    -The video creator uses a MacBook for recording and OBS for capturing the screen. He also uses the 'Continuity Camera' feature of his iPhone to use it as a webcam, which he mounts and uses for video recording. He mentions using video effects and a desk view feature in OBS for additional visual elements.

Outlines

00:00

๐Ÿ“˜ Introduction to String Methods

The script introduces the concept of 'String' methods in programming, akin to the excitement of a Netflix series. It explains the immutability of strings, which means they cannot be changed in-place but can be copied and manipulated to create new strings. The video demonstrates various string operations such as converting to uppercase or lowercase, finding the string length, and stripping trailing characters. It emphasizes the creation of new strings through methods like 'upper()', 'lower()', and 'rstrip()', and introduces the 'replace()' method for substituting occurrences within a string.

05:02

๐Ÿ“š Exploring More String Methods and Replit Tutorial Access

This paragraph delves deeper into additional string methods, including 'split()', 'capitalize()', 'center()', and 'count()', explaining their functionalities and providing examples. The 'split()' method is introduced for dividing strings into lists based on spaces, while 'capitalize()' is highlighted for its utility in blog writing, ensuring the first letter of a string is uppercase. The 'center()' method is showcased for aligning strings, and 'count()' for tallying character occurrences. The script also guides viewers on how to access and utilize the Replit platform for hands-on practice, emphasizing the importance of forking the provided Replit for interactive learning.

10:05

๐Ÿ” Advanced String Methods for String Manipulation

The script continues with a detailed exploration of advanced string methods, such as 'endswith()', 'find()', 'index()', 'isalnum()', 'isalpha()', 'islower()', and 'isprintable().'. It explains how 'endswith()' checks for a substring at the end of a string, while 'find()' locates the index of the first occurrence of a substring, returning -1 if not found. The 'index()' method is noted for raising an error when the substring is absent. 'isalnum()' and 'isalpha()' are introduced to check for alphanumeric and alphabetic characters, respectively, and 'islower()' to verify lowercase characters. 'isprintable()' determines if all characters in a string are printable, excluding non-visible characters like newlines.

15:08

๐Ÿ“ Concluding String Methods and Replit Interface Navigation

The final segment of the script covers the remaining string methods, including 'isspace()', 'istitle()', 'isupper()', 'startswith()', 'swapcase()', and 'title()'. It explains 'isspace()' returns true for strings containing only whitespace, 'istitle()' checks for properly capitalized titles, 'isupper()' for uppercase characters, and 'startswith()' for substrings at the beginning of a string. 'swapcase()' is shown to invert character cases, and 'title()' to capitalize the first letter of each word. The script concludes with a demonstration of the Replit interface, highlighting its smooth navigation and the speaker's preference for using it in the course. It also provides a brief mention of the recording setup used for the video content.

20:08

๐ŸŽฅ Behind-the-Scenes: Recording Setup and Final Thoughts

In the closing paragraph, the speaker shares insights into their video recording setup, addressing frequent inquiries from the audience. They discuss the use of a MacBook for video creation, the utilization of OBS for recording, and the innovative 'Continuity Camera' feature of Apple devices, which allows an iPhone to function as a high-quality webcam. The speaker also touches upon various video effects available for enhancing the visual appeal of the content and provides a quick tour of their desk setup. The paragraph concludes with an appreciation for the viewers and an anticipation for the next video in the series.

Mindmap

Keywords

๐Ÿ’กString Methods

String methods are functions in programming that allow operations to be performed on string data types. In the video, the host introduces various string methods in Python, such as converting strings to uppercase or lowercase, and explains their importance for manipulating text.

๐Ÿ’กImmutability

Immutability refers to the concept that strings in Python cannot be changed after they are created. The host emphasizes that although strings are immutable, new strings can be created by applying methods to the original string. This is crucial for understanding how string methods work in Python.

๐Ÿ’กUppercase

Uppercase refers to converting all characters in a string to capital letters. The host demonstrates how to use the 'upper()' method to transform a string into uppercase, illustrating its usage with the string 'Harry' becoming 'HARRY'.

๐Ÿ’กLowercase

Lowercase refers to converting all characters in a string to small letters. The video shows how to use the 'lower()' method to change an uppercase string to lowercase, which is useful for standardizing text inputs.

๐Ÿ’กrstrip

The 'rstrip' method is used to remove trailing characters from a string. The host explains its application by showing how to remove exclamation marks from the end of the string 'Harry!!!!!!!', making the text cleaner.

๐Ÿ’กreplace

The 'replace' method allows for replacing all occurrences of a substring within a string with another substring. The video uses this method to replace 'Harry' with 'John', demonstrating its effectiveness in text manipulation.

๐Ÿ’กsplit

The 'split' method divides a string into a list of substrings based on a specified delimiter, such as a space. The host briefly mentions this method, noting that it will be discussed further in conjunction with lists.

๐Ÿ’กcapitalize

The 'capitalize' method converts the first character of a string to uppercase and the rest to lowercase. The video highlights its utility in writing, such as ensuring blog titles are properly capitalized for readability.

๐Ÿ’กcount

The 'count' method returns the number of occurrences of a substring within a string. The host shows how this method can be used to count how many times 'Harry' appears in a given string, providing a simple way to analyze text data.

๐Ÿ’กfind

The 'find' method searches for the first occurrence of a substring within a string and returns its index. If the substring is not found, it returns -1. This method is demonstrated to show its practical use in locating specific text within a larger string.

Highlights

The 100 Days Of Code series is compared to a Netflix series in terms of excitement it generates.

Introduction to 'String' methods and their importance in programming.

Explanation of how to perform operations on 'Strings', such as converting to uppercase or lowercase.

Demonstration of finding the length of a 'String' using the len() function.

Concept of immutability in 'Strings' and how it affects in-place modifications.

Illustration of using the upper() and lower() methods to change case in 'Strings'.

Introduction of the rstrip() method to remove trailing characters from a 'String'.

Explanation of the replace() method to substitute all occurrences of a substring.

Introduction to the split() method for converting 'Strings' into lists based on spaces.

Use of the capitalize() method for capitalizing the first letter of a 'String'.

Description of the center() method to align 'Strings' to the center based on a given parameter.

Explanation of the count() method to determine the frequency of characters within a 'String'.

Introduction of the endswith() function to check if a 'String' ends with a specific character or set of characters.

Explanation of the find() method to locate the index of the first occurrence of a substring.

Description of the index() method, which is similar to find() but raises an exception if the substring is not found.

Introduction of the isalnum() method to check if a 'String' consists only of alphanumeric characters.

Explanation of the isalpha() method to determine if a 'String' contains only alphabetic characters.

Introduction of the islower() method to check if all characters in a 'String' are lowercase.

Description of the isprintable() method to determine if all characters in a 'String' are printable.

Explanation of the isspace() method to check for the presence of whitespace in a 'String'.

Introduction of the istitle() method to verify if the first letter of each word in a 'String' is capitalized.

Explanation of the isupper() method, similar to islower(), but for uppercase characters.

Introduction of the startswith() method, counterpart to endswith(), to check the start of a 'String'.

Description of the swapcase() method to invert the case of characters in a 'String'.

Explanation of the title() method to convert a 'String' to title case, capitalizing the first letter of each word.

Details of the recording setup using a MacBook, iPhone, and OBS software.

Transcripts

play00:00

This 100 Days Of Code series is doing just like Netflix

play00:02

People are excited for this just like a TV series

play00:05

It's quite fun!

play00:06

In today's video we'll talk about 'String' methods

play00:09

We already have studied about 'Strings'

play00:11

We learned "What 'String' is" And "It is quite important 'Data Type' "

play00:14

And we also had a look on the ways of creating a 'String'

play00:18

Today I'll tell you how you can do operations with a 'String'

play00:21

For eg. Let's suppose you want to convert a 'String' in Uppercase

play00:24

Or you want to convert a 'String' in lowercase which is written in Uppercase

play00:28

Or you want to find out the length of a string so how you can do that?

play00:31

I'll tell you all this in this video

play00:33

Lets move to the computer screen and let's get started

play00:36

[

play00:36

[S

play00:36

[ST

play00:36

[STA

play00:37

[STAR

play00:37

[START

play00:37

[STARTI

play00:37

[STARTIN

play00:37

[STARTING

play00:37

[STARTING

play00:38

[STARTING T

play00:38

[STARTING TH

play00:38

[STARTING THE

play00:38

[STARTING THEM

play00:38

[STARTING THEME

play00:38

[STARTING THEME]

play00:45

So as You can see I've opened my Repl

play00:47

And if you haven't accessed the play-list so make sure to do it

play00:50

Bookmark it by clicking here

play00:52

And save it by clicking here

play00:53

Today we'll learn about some methods of 'Strings'

play00:55

Let's suppose I've written here ' a = "harry" '

play00:58

This the 'String' of len 5, we all know this

play01:00

In the preceding video we learned, this is how we can print the len(a)

play01:08

There's no big deal in that, we got 5.

play01:10

But what should I do if I want to convert this string into uppercase?

play01:17

The first thing I want to explain you is, "Concept of immutability"

play01:21

This is I want to explain you first

play01:23

'Strings' are immutable

play01:26

Which means you cannot change them

play01:28

But you can change them, It's not about, you can't change them at all

play01:32

But you cannot change them 'in-place' Let me explain

play01:35

Let's suppose I've ' a = "Harry" '

play01:37

So I cannot change variable 'a' as it is

play01:41

It is what it is

play01:43

I can make a copy of it

play01:46

So whenever I apply any method related to 'Strings'

play01:48

For eg. let's suppose if I write here "print(a.upper)"

play01:51

So I'll get a new 'String'

play01:53

I'll get a new 'String' in which all the letters...

play01:58

...Will be of uppercase

play02:00

As you can see I've got "HARRY" in capital letters

play02:03

It's not like the old 'String' has been changed

play02:06

So this is the question they ask in interviews That's why I'm telling you

play02:08

That " 'Strings' are immutable "

play02:11

Let me write this here for reminding you

play02:13

"Strings are immutable"

play02:16

"Strings are immutable"

play02:18

And obviously I'll change it to a comment

play02:20

I'll make it a comment with the help of ( Ctrl + / )

play02:23

So that it won't be executed

play02:25

Because if this gets executed, so it'll throw an error

play02:28

And I don't want it to throw error

play02:30

OK! Good!

play02:31

As I told you about 'Upper' method just like that there's 'Lower' method

play02:35

Which converts our 'String'...

play02:38

...Into lowercase

play02:39

And it is very obvious "The 'lower()' method converts string to lower case."

play02:43

And I also have given an example here if you want to try this out

play02:47

Will this example convert this 'String-1' into lowercase?

play02:51

Do you know the answer to this question?

play02:52

"No! It won't"

play02:53

Why?

play02:54

Because it'll create a new 'String'

play02:58

It won't change the existing 'String'

play03:00

"Strings are immutable in Python" You can't change them

play03:04

But you definitely can create a new 'String' using 'String Methods'

play03:08

What do 'String Methods' do?

play03:09

They operates on you existing 'String' and return a new 'String'

play03:13

We learned this...

play03:14

(a.upper) & (a.lower) What will (a.lower) do?

play03:17

It'll convert whole 'String' "Harry" into lowercase

play03:21

Great!

play03:22

Now there's a method with name "rstrip" Which removes the trailing characters

play03:25

Let's suppose if I had written my name like "Harry!!!!!!!"

play03:29

So if I prints (a.upper) or (a.lower)

play03:32

Or if I print(a) for that matter

play03:35

So I'll directly get my 'String' as it is

play03:37

But I want these exclamation marks to be stripped

play03:41

So I'll write (a.rstrip)

play03:44

What does it do?

play03:45

It strips....

play03:48

...Trailing characters

play03:49

So I can strip exclamation marks like this

play03:52

So look here.....

play03:54

These marks has been striped

play03:55

Does it strip leading exclamation marks?

play03:59

The answer is "No"

play04:01

Exclamation mark will stay on the starting

play04:03

So it just strip trailing characters

play04:07

So we learned this....

play04:08

So I'll leave this "Harry!!!!!!!" as it is so that you can understand about 'rstrips' briefly

play04:13

Now let's talk about 'replace'

play04:15

What does it do?

play04:15

"Replaces all occurrences of a string with another string."

play04:18

Let's suppose I want to replace "harry" with "John"

play04:22

So I'll write "print(a.replace("harry", "John"))

play04:25

Replace "Harry" with what? And obviously I'll write this in double-quotes(" ")

play04:29

Replace all the occurrences of "Harry"...

play04:31

...With...

play04:32

..."John"

play04:33

So now if I prints it, so the 'String' will be printed as it is except "Harry" which will be replaced by "John"

play04:37

As you can see here....

play04:40

What if there were multiple "Harry"? Would all those also change?

play04:42

Yes! As here it is written "all occurrences" so all the "Harry" will be changed to "John"

play04:47

(a.replace("Harry")) all "Harry" have changed to "John"

play04:53

So this is it

play04:53

Now "What does 'Split' do?"

play04:55

'Split' is a quite good method which converts...

play05:02

...Your 'String' into a 'List'

play05:03

Now we haven't studied much about 'List' yet

play05:06

So I won't talk about this method for too long

play05:08

But I will just show you...

play05:10

If I....

play05:12

....Split

play05:14

Split with a 'Space'

play05:16

And my 'String' must contains 'Spaces' only then the 'Split' will work

play05:18

So this will be the first element of 'String' and this will be the second element of 'String'

play05:22

If there's another 'space' so that will be the third element of 'String'

play05:24

Which means a list of this, this & this will be created

play05:29

So let me tell you how this works

play05:31

If I run this so a list will be created

play05:33

Which will contain "!!!Harry!!" , "!!!!!!" and then "Harry"

play05:37

What is 'List'?

play05:38

I'll tell you soon & very clearly

play05:40

We'll also have a look on methods of 'List'

play05:42

'Capitalized' method is.... In JavaScript.... Yes I'm talking about JavaScript

play05:47

'Capitalized' method is not in JavaScript

play05:49

'Capitalized' method is quite useful when you're writing Blogs

play05:51

I remember when I was writing my Blog for "CodeWithHarry.com" in Python Django

play05:56

So at that time this was quite useful to me when I had to capitalize the first character

play06:01

Which means I want to display the first character as capital

play06:04

For eg. let's take the heading of my Blog

play06:06

Let me take realistic example so that it'll be easy for you to understand

play06:11

"introduction to js" let's suppose this is my heading

play06:15

Now I want to capitalize this heading

play06:17

Now you'll say "just correct the spelling yourself what's the need to capitalize it?"

play06:22

So what happens is... We sometime forget to write in capital

play06:25

We usually write like this in a hurry

play06:26

So if I've written the heading of Blog like this in a hurry

play06:29

So I want this heading's first character...

play06:34

...to be converted in uppercase

play06:36

So I'll write "print(blogHeading.capitalize)"

play06:42

And when I'll run this so the first character of my blog will be converted into capital

play06:46

And my Blog will look good

play06:48

So look "Introduction to js" it's first letter is in capital now

play06:52

Which looks quite great

play06:54

So this is how you can do it

play06:56

Now look....

play06:57

If I write the same thing like this....

play07:00

Let's suppose if someone has made a mistake

play07:02

He has write it as "tO" and this mistake is quite common when you're publishing 2-3 Blogs daily

play07:07

So often this human error occurred

play07:09

And let's suppose if you've written it like this....

play07:11

"jS"

play07:12

When you'll run this...

play07:15

So 'Capitalize' will automatically correct it and look it has turned them all into lowercase

play07:20

Now if you move to here and have a look on the description of Capitalize method

play07:25

So you'll see "The capitalize() method turns only the first character of the string to uppercase"

play07:29

It'll convert the first character into uppercase

play07:31

But it'll convert all the other characters into lowercase

play07:35

"The string has no effect if the first character is already uppercase"

play07:39

Which is so obvious

play07:39

And if your first letter is already an uppercase so what can it do?

play07:44

When everything is correct so 'Capitalize' takes no effects

play07:48

But this is how it works

play07:51

Now there comes 'Center' method it aligns the string to the center

play07:56

As per the parameter given

play07:57

So I'll use the same example as here

play08:00

And I'll run this...

play08:01

And when it started printing "Welcome to the console" it automatically added 50 'spaces' in the starting

play08:08

Now let me sow you one thing

play08:09

I'll do " print(len(str1.center(50))) "

play08:14

And I'll do " print(len(str1)) "

play08:20

And if I run it.... So look,

play08:22

Length of (str1) is 25 and length of (str1.center(50)) is 50

play08:26

So what this center do is...

play08:28

The length of string was 25 and it added 25 spaces in starting so that it'll be aligned to the center

play08:35

So this is how 'Center' method works

play08:38

And I also have written the description

play08:40

Now we'll move forward and talk about "count"

play08:42

What 'Count' method does is... It tells which character is occurring how many times in the string

play08:46

For eg. "Harry" is occurring twice here

play08:48

So if I want to count how many times "Harry" is occurring in my string

play08:53

So I can print it like....

play08:55

I'll write "print(a.count("Harry")) "

play08:59

Tell me how many times "Harry" is occurring in string 'a'

play09:02

It is occurring twice so look, it has printed 2

play09:05

So this is how 'Count' method works

play09:07

And then 'endswith()' function is quite useful

play09:10

With this method we can find if a string is ending with given character/set of character

play09:18

Let me show you... And I'll use the same example as here

play09:21

I'll copy and paste this example and let me show you

play09:24

The biggest advantage of using Replit is, that I've written tutorial directly here and you can practice it

play09:30

So Ideally what you have to do is.... Let me tell you because this is the FAQ

play09:34

You firstly have to fork my Repl

play09:39

And after you fork it, you'll be able to run it

play09:41

And you'll see this interface

play09:44

If you access this Repl directly so you won't see this interface

play09:47

You have to 'Fork' the Repl

play09:48

Let me show you because it is very important

play09:51

I've to this because this is very important

play09:54

I'm interrupting this lecture for a sec

play09:57

And I want to show you

play09:59

So if you visit "replit.com/codewithharry"

play10:05

And I've write it like "replit.com/@codewithharry"

play10:08

If yo visit "replit.com/@codewithharry"

play10:10

So for example this is my Repl

play10:12

So what you've to do is, you've to click on "Fork Repl"

play10:16

And when you'll click on "Fork Repl" so you'll see this interface

play10:21

I'm unable to see this interface because I'm not logged in

play10:23

But you'll see this interface

play10:24

So basically happens is.. that a copy of my Repl is created for you

play10:28

And you can edit it as you please

play10:31

So I want to tell you this because it is very important

play10:34

So by doing " print(str1.endswith(!!!)) " It'll tell if this string is ending with this or not

play10:40

So it is ending with this... So I got 'True' as output

play10:42

It'll return this me as a 'Boolean' 'Data Type'

play10:45

I can use 'Boolean' 'Data Type' in (If/Else) Which I'll explain in the upcoming lecture

play10:49

So this is how we can use "endswith()"

play10:52

So look " We can even also check for a value in-between the string by providing start and end index positions. "

play11:00

I can even tell if this string is ending with "To" between character 4 and 10

play11:05

Do you understand what this means? Let me explain you

play11:08

Look, if I do slicing of this string

play11:11

And if I search from 4 to 10 so what will I get?

play11:14

0...1...2...3...

play11:17

And I'll get the text I've highlighted

play11:20

I'll get "ome to"

play11:23

So is this string ending with "to" ?

play11:27

Yes! It is ending with "to" so I'll get "True" as output

play11:29

So look if I run this...

play11:31

And BTW for you information let me tell you that I can over-write a variable

play11:35

In Python Programming like this

play11:37

So I've got 'True' here

play11:40

So this is how it works

play11:42

Now let's talk about 'Find' methods

play11:44

'Find' method is a quite simple method which search for the first occurrences of the given value

play11:49

And it returns the index where it is present

play11:52

So I'd like to tell you, if it is unable to find the string you're looking for

play11:59

So it returns "-1"

play12:00

You won't get it like this, so let me give you an example

play12:03

So look here's a man with name "Dan" "He's name is Dan" is written here

play12:10

"He is an honest man"

play12:11

Now you'll say "Why have you written 'He's name is...' "

play12:14

Let me tell you

play12:15

It won't detect this

play12:17

But it will detect this

play12:19

In-fact it'll detect this because this is the first occurrence

play12:21

So let me show you if we use 'Find()' method so I'll get it's index 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

play12:28

I should get output " 10 "

play12:29

And I'm getting output " 10 "

play12:31

So it'll return me the index of the first occurrence of "is"

play12:36

So if I do " print(str1.find("is")) " so it'll return me the index of first occurrence of "is"

play12:40

It won't show this or this... because this is not "is" and Python don't know, because Python is not a human

play12:47

Python is not a human or Snake

play12:49

Python is an... interpreter or a computer

play12:53

So it can compute...

play12:55

It cannot detect that "He's" also means "He is "

play12:58

So it'll give me the index where it'll literally find first "is"

play13:03

Now the next method I want to mention is "Index" method, What is it?

play13:07

Index method is basically same... in-fact it is quite similar to "Find" method

play13:12

But what 'Find' does is... It return "-1" If I search for "ishh" so it'll return "-1"

play13:18

Because there's no occurrence of "ishh" so it'll return "-1"

play13:21

But if I copy this and change this with "index"

play13:25

So an exception will be raised

play13:27

And I'll get an error

play13:29

So maybe if we're so sure in our program to find something so we'll use this method

play13:35

But if we want our program to exit after giving an error if it's unable to find this

play13:39

SO we'll use 'index' method

play13:41

So 'Index' method raise an exception

play13:44

"ValueError: substring not found" so this is the error it raise

play13:52

And then comes the next method 'isalnum()' to find if your string is alpha numerical or not

play14:00

"The isalnum() returns True only if the entire string only consists of A-Z, a-z, 0-9."

play14:04

These are the alpha numeric characters

play14:06

"If any other characters or punctuations are present, then it returns False.

play14:10

As you can see if I run it...

play14:12

"Welcome to the console"

play14:14

Yes! Let me comment his out because it is throwing error

play14:18

I'll comment this out because there is no occurrence of "ishh"

play14:20

There is no occurrence of "ishh" so it is throwing error

play14:22

So look it is an alpha numeric string so the output is 'True'

play14:24

Alpha numeric means an 'String' made up of "A-Z, a-z, 0-9" these character

play14:32

And then comes "isalpha" but it doesn't contains numbers unlike "isalnum"

play14:37

"isalpha" will return 'True' if your 'string' consist "A-Z or a-z"

play14:44

Else it'll return 'False'

play14:45

This time I'll give you example with "Welcome00" if it returns 'False' or not

play14:50

Now if I check for "welcome00" so it'll return 'False' but earlier it was returning 'True'

play14:55

I hope I'm not explaining this very fast

play14:56

So look the output is 'False'

play14:57

But if I remove these double-zero(00)

play14:59

So 'True' will be returned in place of 'False'

play15:02

And try this on your own

play15:04

If you don't so there won't be any clarity

play15:07

Then comes 'islower' to check if all the characters are of lowercase or not

play15:12

If yes, it'll return 'True' or else 'False'

play15:15

So look, you've got this Repl and you know that you'll get this interface when you'll fork it

play15:20

You can place it wherever you want like this

play15:25

This navigation is so smooth

play15:27

That's why I've choose Replit for this course

play15:30

Because it is fun

play15:31

Here appears the tutorial and here Floating video I don't think we can find better experience than this as of now

play15:37

Then 'isprintable' is the next method

play15:40

Try 'islower' if it is made up of lowercase so it'll return 'true'

play15:44

Or if I there's any uppercase character so it'll return 'False'

play15:50

I'll press ( Ctrl + Z ) and this will be returned to 'True'

play15:53

As you can see

play15:55

Now what is 'isprintable()'

play15:57

"The isprintable() method returns 'True' if all the values within the given strings are printable"

play16:01

Otherwise it returns 'False'

play16:04

So it'll return 'True' if character is printable or else 'False'

play16:07

I just want to show you the printable characters and all these characters are printable so it'll return 'True'

play16:12

But if I add a carriage return back-slash(n)

play16:15

So it'll return 'False'

play16:16

Because this is not a printable character you won't be able to see back-slash(n)

play16:20

So that why 'False'....

play16:20

If I print...

play16:23

...str1

play16:24

So you won't be able to see back-slash(n)

play16:27

You'll literally get the new line printed

play16:30

back-slash(n) is not one of printable characters

play16:33

So I hope you understood this

play16:36

Now I'll tell you about 'isspace()' method

play16:39

"This returns 'True' only and only if the string contains white spaces

play16:43

Otherwise it returns 'False'

play16:44

So if we've added white spaces using space-bar

play16:49

So you'll 'True' in return

play16:51

So look I've added spaces with space-bar like this

play16:55

And it is returning 'True'

play16:57

Even if I use 'Tab' key for spaces they'll be count as 'white spaces'

play17:02

So are there spaces present?

play17:05

Yes there are! So it is returning 'True'

play17:08

True True

play17:09

I hope you got this

play17:11

Now there's a method 'istitle()' which returns 'True' only if the first letter of each word of the string is capitalized

play17:17

Else it returns 'False'

play17:19

So what can we do?

play17:20

I remember I used this method in my Django Blog when I....

play17:24

...had to capitalize all the titles of my Blog

play17:30

And if there's a character which is not capital so I can find that in my dashboard

play17:36

So I can do that...

play17:38

If I run this... So my iPhone is also telling me that I only got 20% battery level

play17:43

Please finish the video quickly

play17:45

BTW many of you wants to know that how am I recording?

play17:47

So I use 'continuity camera' of iPhone

play17:50

Because I was getting too much messages about this, that's why I'm telling you this

play17:53

It's quite great... So I'll talk about this in the end of video so that no one's time get wasted

play17:56

Let me finish this title quickly

play18:00

"To kill a Mocking bird"

play18:01

I have to check if this falls under 'istitle' or not

play18:04

So I can do that in this way

play18:06

And look... "To kill a Mocking bird" "False"

play18:11

Now what does 'isupper' do?

play18:13

Exactly as 'islower'

play18:16

Now the next method is 'startswith()' Which is exactly like 'endswith'

play18:19

If your string is starting with the given character so it'll return 'True'

play18:26

So look the output will be 'True' because it is starting with 'True'

play18:30

Now the next method is 'swapcase()' which swaps the uppercase to lowercase and vice-versa

play18:35

A very straight forward method, try to run & practice it

play18:39

'swapcase()'

play18:40

So look it has swap all the case

play18:42

It has swapped uppercase to lower and vice-versa

play18:44

Now there's a 'title()' method which converts it to a 'titlecase'

play18:49

Look what's happening is... when I'll run it...

play18:52

So "He's name is Dan"

play18:55

Let me change this to 'His'

play18:57

"His name is Dan" "And Dan is an honest man"

play19:00

Now all the first characters will be tuned to uppercase just like 'I' & 'D'

play19:07

So this is used usually in Blogs

play19:10

I hope you've understood this quite well

play19:14

And now for the ones who want to know about my recording set-up because I was getting too many questions

play19:19

And for the rest ones, we'll meet in the video

play19:22

This is all about coding for now

play19:23

Now I'll tell about my recording set-up The one who wants to.. will listen

play19:27

Rest of you can skip to next video, if any

play19:29

So look, what I do is... This is my MacBook

play19:32

I bought a MacBook recently

play19:34

To create videos

play19:36

I bought this because I was quite impress with the MacBook and I was using it in my work space and it impresses me quite a lot

play19:41

So I bought MacBook because I got used to it

play19:44

I often used to get confused while doing office work & personal work

play19:48

So I choose to stay on MacBook

play19:51

Is something wrong with Windows? No! It's great

play19:53

And I recommend you to start with Windows

play19:56

Well we'll leave these discussion for another video

play19:58

But I record with OBS

play20:00

And there's a feature in your iPhone with name 'Continuity Camera'

play20:03

What it does is...

play20:05

Let me show you continuity camera

play20:08

If you own a MacBook and an iPhone

play20:11

So when you bring you iPhone closer to your MacBook and turn on it's Bluetooth & Wi-fi

play20:17

So your iPhone can automatically be used as a Web-cam

play20:21

So look how good the quality is.. It is my iPhone

play20:25

So I tried it.. I also have got a camera maybe you can see, it's behind me

play20:29

I can use it too, and I've a variety of lenses

play20:32

The quality can be improved

play20:34

But again I'm pretty satisfied with iPhone's quality

play20:37

So I've mounted my iPhone here

play20:40

And the rest is too easy

play20:43

Now there are quite impressive things in it that you have the option for video effects

play20:48

So look if I choose the option 'Center Image' so look the image has moved to the center

play20:52

And if I click on 'Portrait' let me show you how am I doing this

play20:55

If you click here so you'll get an option for 'Video effects'

play20:58

So there are 3 options let me show'em all

play21:01

The first one is already in use

play21:04

Now I've chosen the second one

play21:05

Now if I choose 'Studio Light' so the lighting is changing

play21:08

When I'll use 'Portrait' so it's get blurred

play21:10

But it is good enough, I think it shouldn't blur this mic

play21:13

And if I move like this so this is good and it also has blurred the stand of mic

play21:16

So I know Apple will do improvement in this

play21:20

But...

play21:22

It's quite great, and let me turn off these effects because I use them while post processing

play21:26

So I turned off these effects because I use them while post processing

play21:29

Then comes the 'Desk view' in this you'll be able to see my desk

play21:32

Now you're able to see my desk. Can you see it?

play21:37

So this is quite good, you're able to see all the material of my desk

play21:42

This desk view is visible

play21:46

This is quite impressive

play21:48

Can you see which angle is it using?

play21:51

So let me close it for now

play21:53

And that's all... I just have used this mic

play21:57

Which is quite great

play21:58

Normal mic was enough but I've upgraded this

play22:02

I hope you're enjoying it

play22:03

When the quality is good, it's fun watching videos

play22:06

That's it for this video guys. Thank you so much guys for watching this video :)

play22:10

And I'll see you next time

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Python TutorialString MethodsImmutabilityText ManipulationCoding SeriesData TypeUppercaseLowercaseSubstringReplitEducational