Skip to content

Strings

String Formatting

name="string formating"
print("string %s %s %d " % (name,name, age) )
print("string {}".format(name))
print(f"string {name}")
print(f"string {name}")
print(f"{text:*>10}")                       # ******text
print(f"{text:*^10}")                       # ***text***
print(r"na/////z{}(}{(!{!}##!@--()])))})")  # raw print 

String Manipulation

name="string formating"

name.strip().upper().lower()
name.replace('e','o').split(' ').find('str').index('str').count('str')
name.startsWith('H').endsWith('H').isalpha().isdigit().isspace().islower()

print(' '.join(my_list))

table_change=str.maketrans('sf','SF')
new_name=name.translate(table_change)
Docs

https://docs.python.org/3/library/string.html