String Examples Flashcards
print(“hello and welcome!”.capitalize())
Hello and welcome!
print(“Hello And Welcome!”.casefold())
hello and welcome!
print(“hello”.center(10, ‘m’))
mmhellommm
print(“hello”.center(11, ‘m’))
mmmhellommm
print(“hello”.center(5, ‘m’))
hello
print(“apples to apples”.count(‘apple’))
2
print(‘Hello!’.endswith(‘!’))
True
print(‘Hello boy!’.endswith(‘boy!’, 3,7))
False
print(‘Hello boy!’.endswith(‘boy!’, 6,10))
True
txt = “H\te\tl\tl\to”
x = txt.expandtabs(2)
print(x)
H e l l o
txt = “H\te\tl\tl\to”
x = txt.expandtabs(4)
print(x)
#3 spaces in between H e l l o
print(“Hello, welcome to my world.”.find(“welcome”))
7
print(“This code is written in {}”.format(“Python”))
This code is written in Python
txt = “Hello, welcome to my world.”
x = txt.index(“welcome”)
print(x)
7
txt = “Company12”
x = txt.isalnum()
print(x)
True
txt = “CompanyX”
x = txt.isalpha()
print(x)
True
txt = “\u0033” #unicode for 3
x = txt.isdecimal()
print(x)
True
txt = “50800”
x = txt.isdigit()
print(x)
True