0% found this document useful (0 votes)
5 views

Python String Functions

Python string function hand writing

Uploaded by

kanil648080
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python String Functions

Python string function hand writing

Uploaded by

kanil648080
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

String Functions

Made By:

Yadneyesh (Curious Coder) Find More PDFs on Our Telegram Channel


CodWithCurious.com @Curious_Coder

Method Description Example Output

Converts all
lowercase letters
str.upper() "hello".upper() "HELLO"
in a string to
uppercase.

Converts all
uppercase letters
str.lower() "HELLO".lower() "hello"
in a string to
lowercase.

Capitalizes the
"hello
str.capitalize() first character of "Hello world"
world".capitalize()
the string.

Capitalizes the
"hello
str.title() first letter of each "Hello World"
world".title()
word in the string.

Removes leading
and trailing
str.strip([chars]) characters " hello ".strip() "hello"
(whitespace by
default).

500+ Coding Projects with Source


We Post CSE Notes for You
Code Visit: CodeWithCurious.com
Splits the string into
str.split(sep=No a list of substrings "hello
["hello", "world"]
ne, maxsplit=-1) based on a world".split()
delimiter.

Joins the elements


of an iterable into a
single string, " ".join(["hello",
str.join(iterable) "hello world"
separated by the "world"])
string on which it is
called.

Returns the lowest


index in the string "hello
str.find(sub[,
where substring sub world".find("worl 6
start[, end]])
is found, or -1 if not d")
found.

str.startswith(pr Returns True if the "hello


efix[, start[, string starts with the world".startswith True
end]]) specified prefix. ("hello")

str.endswith(suf Returns True if the "hello


fix[, start[, string ends with the world".endswith(" True
end]]) specified suffix. world")

Returns True if all


characters in the
str.isalpha() "hello".isalpha() True
string are
alphabetic.

500+ Coding Projects with Source


We Post CSE Notes for You
Code Visit: CodeWithCurious.com
Returns True if
all characters
str.isdigit() "12345".isdigit() True
in the string are
digits.

Returns True if
all characters "hello123".isalnu
str.isalnum() True
in the string are m()
alphanumeric.

Returns the
number of non-
"hello
str.count(sub[, overlapping
world".count("o" 2
start[, end]]) occurrences of
)
substring sub in
the string.

Formats the "Hello, {}. You


Hello, Alice. You
str.format(*arg string using the are {} years
are 30 years
s, **kwargs) provided old.".format("Ali
old.
arguments. ce", 30)

name = "Alice";
Formats strings
age = 30; Hello, Alice. You
using
f-string f"Hello, {name}. are 30 years
embedded
You are {age} old.
expressions.
years old."

500+ Coding Projects with Source


We Post CSE Notes for You
Code Visit: CodeWithCurious.com

You might also like