[go: up one dir, main page]

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

Upper Case

Uploaded by

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

Upper Case

Uploaded by

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

Upper Case

The upper() method returns the string in upper case:

a = "Hello, World!"
print(a.upper())

Lower Case
The lower() method returns the string in lower case:

a = "Hello, World!"
print(a.lower())

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

The strip() method removes any whitespace from the beginning or the
end:

a = " Hello, World! "


print(a.strip()) # returns "Hello, World!"

Replace String
The replace() method replaces a string with another string:

a = "Hello, World!"
print(a.replace("H", "J"))

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 = "Hello, World!"
print(a.split(",")) # returns ['Hello', ' World!']

But we can combine strings and numbers by using the format() method!

The format() method takes the passed arguments, formats them, and places
them in the string where the placeholders {} are:

Example
Use the format() method to insert numbers into strings:

age = 36
txt = "My name is John, and I am {}"
print(txt.format(age))

You might also like