Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Mastering Python String Modifying

The document provides an overview of built-in string modification methods in Python, including upper(), lower(), strip(), replace(), and split(). Each method is explained with examples demonstrating their functionality. Additional resources for learning about Python strings are also mentioned.

Uploaded by

fatmamahdy82
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)
4 views

Mastering Python String Modifying

The document provides an overview of built-in string modification methods in Python, including upper(), lower(), strip(), replace(), and split(). Each method is explained with examples demonstrating their functionality. Additional resources for learning about Python strings are also mentioned.

Uploaded by

fatmamahdy82
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/ 5

@ilyasqasim

Python
Modify
Strings

resources: www.w3schools.com
01
Python Modify Strings
Python has a set of built-in methods that you can use on
strings.
Upper Case
The upper() method returns the string in upper case:
a = "Python, World!"
print(a.upper())

Result:
PYTHON, WORLD!

Lower Case
The lower() method returns the string in lower case:
a = "Python, World!"
print(a.lower())

Result:
python, world!

@ilyasqasim resources: www.w3schools.com


02
Remove Whitespace
Whitespace is the space before and/or after the actual text, and
very often you want to remove this space.

2
The strip() method removes any whitespace from the beginning
or the end:
a = " Python, World! “
print(a.strip())

Result:
Python, World!

Replace String
The replace() method replaces a string with another string:
a = " Python, World! “
print(a.replace(“o”, “a”))

Result:
Pythan, Warld!

@ilyasqasim resources: www.w3schools.com


03
Split String
The split() method returns a list where the text between the
specified separator becomes the list items.
The split() method splits the string into substrings if it finds
instances of the separator:
a = "Python, World!" The split() method splits a string into a
print(a.split(“,”)) list:
Split a string into a list where each word is a
list item
Result:
You can specify the separator, default
['Python', ' World!'] separator is any whitespace.

"CURIOUS ABOUT PYTHON


STRINGS?
ASK IN THE COMMENTS
AND I'LL SHARE THE
COMPREHENSIVE LIST OF
BUILT-IN METHODS WITH
EXPLANATIONS!"

@ilyasqasim resources: www.w3schools.com


J
O
LIKE COMMENT REPOST SHARE

I Learn to Code
@ilyasqasim

resources:
www.w3schools.com

You might also like