0% found this document useful (0 votes)
10 views2 pages

6.1 StringMethods-01.pdf

The document provides an overview of common string methods in Python, detailing their functionality and usage. It includes methods such as len(), str.capitalize(), str.count(), and str.find(), along with examples of input and output. For a comprehensive list of string methods, it directs readers to the official Python documentation.

Uploaded by

shuklaram481
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

6.1 StringMethods-01.pdf

The document provides an overview of common string methods in Python, detailing their functionality and usage. It includes methods such as len(), str.capitalize(), str.count(), and str.find(), along with examples of input and output. For a comprehensive list of string methods, it directs readers to the official Python documentation.

Uploaded by

shuklaram481
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON COMMON STRING METHODS

The Python STRING type contains various methods that can be used to interface with string values. Below is a list of
some of these methods.

Method Description
len() Returns the length of the string. (Not exclusive to string
types.

IN: len(“Python”)
OUT: 6
str.capitalize() Returns a copy of the string with its first character
capitalized and the rest lowercased.

IN: “python is awesome”.capitalize()


OUT: “Python is awesome”
str.count(sub,[start],[end]) Returns the number of non-overlapping occurrences of
substring

IN: “school”.count(“o”)
OUT: 2
str.find(sub,[start],[end]) Returns the lowest index in the string where substring sub
is found within the string.

IN: “school”.find(“o”)
OUT: 3
str.isalpha() Returns true if all characters in the string are alphabetic
and there is at least one character.

IN: “Python”.isalpha()
OUT: True
IN: “Python3”.isalpha()
OUT: False
str.isdigit() Returns true if all characters in the string are digits and
there is at least one character.

IN: “123”.isdigit()
OUT: True
IN: “123a”.isdigit()
OUT: False
str.upper() Returns a copy of the string with all the cased characters
converted to uppercase.

IN: “python”.upper()
OUT: “PYTHON”
str.lower() Returns a copy of the string with all the cased characters
converted to lowercase.

IN: “PYTHON”.lower()
OUT: “python”
str.split([sep], [maxsplit]) Returns a list of the words in the string, using sep as the
delimiter string.
IN: “String,Methods”.split(“,”)
OUT: [“String”, “Methods”]
str.strip([chars]) Returns a copy of the string with the leading and trailing
characters removed.

IN: “ python “.strip()


OUT: “python”
Str.title() Return a titlecased version of the string where words
start with an uppercase character and the remaining
characters are lowercase.

IN: “python is awesome”.title()


OUT: “Python Is Awesome”

For a complete list of String Methods, visit: https://docs.python.org/2/library/stdtypes.html#string-methods

You might also like