String Examples Flashcards

1
Q

print(“hello and welcome!”.capitalize())

A

Hello and welcome!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

print(“Hello And Welcome!”.casefold())

A

hello and welcome!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

print(“hello”.center(10, ‘m’))

A

mmhellommm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

print(“hello”.center(11, ‘m’))

A

mmmhellommm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

print(“hello”.center(5, ‘m’))

A

hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

print(“apples to apples”.count(‘apple’))

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

print(‘Hello!’.endswith(‘!’))

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

print(‘Hello boy!’.endswith(‘boy!’, 3,7))

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

print(‘Hello boy!’.endswith(‘boy!’, 6,10))

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

txt = “H\te\tl\tl\to”

x = txt.expandtabs(2)

print(x)

A

H e l l o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

txt = “H\te\tl\tl\to”

x = txt.expandtabs(4)

print(x)

A
#3 spaces in between
H   e   l   l   o
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

print(“Hello, welcome to my world.”.find(“welcome”))

A

7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

print(“This code is written in {}”.format(“Python”))

A

This code is written in Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

txt = “Hello, welcome to my world.”

x = txt.index(“welcome”)

print(x)

A

7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

txt = “Company12”

x = txt.isalnum()

print(x)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

txt = “CompanyX”

x = txt.isalpha()

print(x)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

txt = “\u0033” #unicode for 3

x = txt.isdecimal()

print(x)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

txt = “50800”

x = txt.isdigit()

print(x)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

txt = “Demo”

x = txt.isidentifier()

print(x)

A

True

20
Q

txt = “hello world!”

x = txt.islower()

print(x)

A

True

21
Q

txt = “565543”

x = txt.isnumeric()

print(x)

A

True

22
Q

txt = “Hello! Are you #1?”

x = txt.isprintable()

print(x)

A

True

23
Q

txt = “ “

x = txt.isspace()

print(x)

A

True

24
Q

txt = “Hello, And Welcome To My World!”

x = txt.istitle()

print(x)

A

True

25
Q

txt = “THIS IS NOW!”

x = txt.isupper()

print(x)

A

True

26
Q

myTuple = (“John”, “Peter”, “Vicky”)

x = “#”.join(myTuple)

print(x)

A

John#Peter#Vicky

27
Q

txt = “banana”

x = txt.ljust(20)

print(x, “is my favorite fruit.”)

A
#There's 15 spaces between 'banana' and 'is'
banana              is my favorite fruit.
28
Q

txt = “Hello my FRIENDS”

x = txt.lower()

print(x)

A

hello my friends

29
Q
#5 spaces to the left and right of banana
txt = "     banana     "

x = txt.lstrip()

print(“of all fruits”, x, “is my favorite”)

A
#1 space to the left of banana and 5 to the right
of all fruits banana     is my favorite
30
Q

txt = “I could eat bananas all day”

x = txt.partition(“bananas”)

print(x)

A

(‘I could eat ‘, ‘bananas’, ‘ all day’)

31
Q

txt = “I like bananas”

x = txt.replace(“bananas”, “apples”)

print(x)

A

I like apples

32
Q

txt = “Mi casa, su casa.”

x = txt.rfind(“casa”)

print(x)

A

12

33
Q

txt = “Mi casa, su casa.”

x = txt.rindex(“casa”)

print(x)

A

12

34
Q

txt = “banana”

x = txt.rjust(20)

print(x, “is my favorite fruit.”)

A
#14 spaces to the left of 'banana'
              banana is my favorite fruit.
35
Q

txt = “I could eat bananas all day, bananas are my favorite fruit”

x = txt.rpartition(“bananas”)

print(x)

A

(‘I could eat bananas all day, ‘, ‘bananas’, ‘ are my favorite fruit’)

36
Q

txt = “apple, banana, cherry”

x = txt.rsplit(“, “)

print(x)

A

[‘apple’, ‘banana’, ‘cherry’]

37
Q
#5 spaces to the left and right of 'banana'
txt = "     banana     "

x = txt.rstrip()

print(“of all fruits”, x, “is my favorite”)

A
#5 spaces to the left of banana and 1 to the right
of all fruits     banana is my favorite
38
Q

txt = “welcome to the jungle”

x = txt.split()

print(x)

A

[‘welcome’, ‘to’, ‘the’, ‘jungle’]

39
Q

txt = “Hello My Name Is PETER”

x = txt.swapcase()

print(x)

A

hELLO mY nAME iS peter

40
Q

txt = “Welcome to my world”

x = txt.title()

print(x)

A

Welcome To My World

41
Q

txt = “Hello my friends”

x = txt.upper()

print(x)

A

HELLO MY FRIENDS

42
Q

txt = “50”

x = txt.zfill(4)

print(x)

A

0050

43
Q

txt = “50”

x = txt.zfill(5)

print(x)

A

00050

44
Q

print(‘banana’.ljust(15),”is my favorite fruit.”)

A
#10 spaces to the right of 'banana'
banana          is my favorite fruit.
45
Q

txt = ‘what up dawg’
a,b,c = txt.split()
print(b)

A

up