Showing posts with label capitalize(). Show all posts
Showing posts with label capitalize(). Show all posts

Jun 22, 2020

Python String Methods | Coding Winds

Python String Method

Python strings capitalize ()

Python capitalize () method converts the first letter of the first string into uppercase and the rest to lowercase.

The syntax is,


Capitalize () doesn’t take any argument.


Non-alphabetic first character will work except there will be no uppercase conversion. (Curious, check it out on your own.)

Python string center ()

It returns the string which is padded with a specific character.

The syntax is,


Width – length of the string with padded character.

Fillchar (optional) - padding character

With the Fillchar, “*


Check for the default case on your own to get in practice.

Python String casefold ()

It is basically used to compare the 2 string regardless of their orientation and changes all the strings to lower case.

The syntax is,


It is used as the same way we used capitalize(). This also doesn’t take any argument.


Python String count()

It returns the number of occurrences of a substring in the given string.

Its syntax is,


Example,

<div class="code">
Paste your code/syntax here
</div>

 

 Python string endswith()

It return True when the suffix is present in the string provided.

Its syntax is,


Suffix will be the strings or tuple to be checked. Start and end will be the indexing for a specific range.

Check out the example,

Output,

We can do this same with the tuple, it works as if the end is present in any item of a tuple, the compiler will give a True output.

Output will be,


If we need to check if a string starts with a specific prefix, we can use startswith() 

Python string expandtabs()

Returns a copy of string with all the tab character,'\t', replaced by white space.

 


Hello Python people, for this blog we have taken help from the book Python : The Complete Reference.


Hope all your doubts regarding this are clear now.

If you still have any doubt on this topic then do come to us via email "sophomoretechs@gmail.com" or via Instagram "@coding.winds".


Do subscribe to our daily blog update by clicking here.


Thank You!