String Examples Flashcards

(45 cards)

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)

20
Q

txt = “hello world!”

x = txt.islower()

print(x)

21
Q

txt = “565543”

x = txt.isnumeric()

print(x)

22
Q

txt = “Hello! Are you #1?”

x = txt.isprintable()

print(x)

23
Q

txt = “ “

x = txt.isspace()

print(x)

24
Q

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

x = txt.istitle()

print(x)

25
txt = "THIS IS NOW!" x = txt.isupper() print(x)
True
26
myTuple = ("John", "Peter", "Vicky") x = "#".join(myTuple) print(x)
John#Peter#Vicky
27
txt = "banana" x = txt.ljust(20) print(x, "is my favorite fruit.")
``` #There's 15 spaces between 'banana' and 'is' banana is my favorite fruit. ```
28
txt = "Hello my FRIENDS" x = txt.lower() print(x)
hello my friends
29
``` #5 spaces to the left and right of banana txt = " banana " ``` x = txt.lstrip() print("of all fruits", x, "is my favorite")
``` #1 space to the left of banana and 5 to the right of all fruits banana is my favorite ```
30
txt = "I could eat bananas all day" x = txt.partition("bananas") print(x)
('I could eat ', 'bananas', ' all day')
31
txt = "I like bananas" x = txt.replace("bananas", "apples") print(x)
I like apples
32
txt = "Mi casa, su casa." x = txt.rfind("casa") print(x)
12
33
txt = "Mi casa, su casa." x = txt.rindex("casa") print(x)
12
34
txt = "banana" x = txt.rjust(20) print(x, "is my favorite fruit.")
``` #14 spaces to the left of 'banana' banana is my favorite fruit. ```
35
txt = "I could eat bananas all day, bananas are my favorite fruit" x = txt.rpartition("bananas") print(x)
('I could eat bananas all day, ', 'bananas', ' are my favorite fruit')
36
txt = "apple, banana, cherry" x = txt.rsplit(", ") print(x)
['apple', 'banana', 'cherry']
37
``` #5 spaces to the left and right of 'banana' txt = " banana " ``` x = txt.rstrip() print("of all fruits", x, "is my favorite")
``` #5 spaces to the left of banana and 1 to the right of all fruits banana is my favorite ```
38
txt = "welcome to the jungle" x = txt.split() print(x)
['welcome', 'to', 'the', 'jungle']
39
txt = "Hello My Name Is PETER" x = txt.swapcase() print(x)
hELLO mY nAME iS peter
40
txt = "Welcome to my world" x = txt.title() print(x)
Welcome To My World
41
txt = "Hello my friends" x = txt.upper() print(x)
HELLO MY FRIENDS
42
txt = "50" x = txt.zfill(4) print(x)
0050
43
txt = "50" x = txt.zfill(5) print(x)
00050
44
print('banana'.ljust(15),"is my favorite fruit.")
``` #10 spaces to the right of 'banana' banana is my favorite fruit. ```
45
txt = 'what up dawg' a,b,c = txt.split() print(b)
up