Strings In Python

Strings In Python

In python Strings are immutable data types, that means we cannot modify an object after it is created, to modify strings we have to again create a string object during runtime. Fire up python shell by typing python3 on terminal. To create string in python we simply assign it to any variable.

In this tutorial we will learn about diffrent methods of python strings that are as follows :

Capitalize Method in Strings

Capitalize method is used for change string character case to capital letters, it change first occurence of string character into capital letter. It does not take any parameters while calling on string object, for example :

Count Method in Strings

Count method counts the number of times character has appeared in string. For example in 'take-exams' string character 'e' has appeared 2 times.It takes one parameter characters to count. Here, you can also pass more than one characters or subset of strings, for example :

Casefold Method in Strings

Casefold method in strings converts mixture of capital and small characters of string into small characters of comparison, it does not take any arguments, for example:

Endswith Method in Strings

Endswith method takes substring or character and returns true or false based on string ends with hat can also define position of string character from where it start searching, for example:

Expandtabs Method in Strings

Expandtabs takes one arguments tabsize, which we specify to seprate strings by not of space characters by default tabsize is of length 8. For example:

Leave a Comment