Regular Expressions in Python
Maria Eugenia Inzaugarat
Data Scientist
my_string = "tHis Is a niCe StriNg"
print(my_string.lower())
this is a nice string
print(my_string.upper())
THIS IS A NICE STRING
my_string = "tHis Is a niCe StriNg"
print(my_string.capitalize())
This is a nice string
my_string = "This string will be split"
my_string.split(sep=" ", maxsplit=2)
['This', 'string', 'will be split']
my_string.rsplit(sep=" ", maxsplit=2)
['This string will', 'be', 'split']
my_string = "This string will be split\nin two"
print(my_string)
This string will be split
in two
my_string = "This string will be split\nin two"
my_string.splitlines()
['This string will be split', 'in two']
my_list = ["this", "would", "be", "a", "string"]
print(" ".join(my_list))
this would be a string
.strip()
my_string = " This string will be stripped\n"
my_string.strip()
'This string will be stripped'
my_string = " This string will be stripped\n"
my_string.rstrip()
' This string will be stripped'
my_string.lstrip()
'This string will be stripped\n'
Regular Expressions in Python