Python String Methods Flashcards

(52 cards)

1
Q

Converts the first character to upper case

A

capitalize()

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

Converts string into lower case

A

casefold()

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

Returns a centered string

A

center()

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

Returns the number of times a specified value occurs in a string

A

count()

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

Returns an encoded version of the string

A

encode()

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

Returns true if the string ends with the specified value

A

endswith()

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

Returns true if the string ends with the specified value

A

endswith()

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

Sets the tab size of the string

A

expandtabs()

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

Searches the string for a specified value and returns the position of where it was found

A

find()

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

Formats specified values in a string

A

format()

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

Formats specified values in a string

A

format_map()

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

Searches the string for a specified value and returns the position of where it was found

A

index()

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

Returns True if all characters in the string are alphanumeric

A

isalnum()

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

Returns True if all characters in the string are in the alphabet

A

isalpha()

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

Returns True if all characters in the string are ascii characters

A

isascii()

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

Returns True if all characters in the string are decimals

A

isdecimal()

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

Returns True if all characters in the string are digits

A

isdigit()

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

Returns True if the string is an identifier

A

isidentifier()

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

Returns True if all characters in the string are lower case

A

islower()

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

Returns True if all characters in the string are numeric

A

isnumeric()

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

Returns True if all characters in the string are numeric

21
Q

Returns True if all characters in the string are printable

A

isprintable()

22
Q

Returns True if all characters in the string are whitespaces

23
Q

Returns True if the string follows the rules of a title

24
Returns True if all characters in the string are upper case
isupper()
25
Converts the elements of an iterable into a string
join()
25
Converts the elements of an iterable into a string
join()
26
Returns a left justified version of the string
ljust()
27
Converts a string into lower case
lower()
28
Returns a left trim version of the string
lstrip()
29
Returns a translation table to be used in translations
maketrans()
30
Returns a tuple where the string is parted into three parts
partition()
31
Returns a string where a specified value is replaced with a specified value
replace()
32
Searches the string for a specified value and returns the last position of where it was found
rfind()
33
Searches the string for a specified value and returns the last position of where it was found
rindex()
34
Returns a right justified version of the string
rjust()
35
Returns a tuple where the string is parted into three parts
rpartition()
36
Splits the string at the specified separator, and returns a list
rsplit()
37
Returns a right trim version of the string
rstrip()
38
Splits the string at the specified separator, and returns a list
split()
39
Splits the string at line breaks and returns a list
splitlines()
40
Returns true if the string starts with the specified value
startswith()
41
Returns a trimmed version of the string
strip()
42
Swaps cases, lower case becomes upper case and vice versa
swapcase()
43
Converts the first character of each word to upper case
title()
44
Returns a translated string
translate()
45
Converts a string into upper case
upper()
46
Fills the string with a specified number of 0 values at the beginning
zfill()
47
Fills the string with a specified number of 0 values at the beginning
zfill()
48
How do string methods affect the string?
All string methods returns new values. They do not change the original string.
49
How do you assign strings to a variable?
* Assigning a string to a variable is done with the variable name followed by an equal sign and the string: a = "Hello" * You can assign a multiline string to a variable by using three double or singe quotes: a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" * OR a = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'''
50
How would you check if a character, word or phrase is in a string?
* To check if a certain phrase or character is NOT present in a string, we can use the keyword not in. txt = "The best things in life are free!" print("expensive" not in txt) * OR txt = "The best things in life are free!" if "expensive" not in txt: print("No, 'expensive' is NOT present.")