String Methodz Flashcards

1
Q

.capitalize()

A

Converts the first letter in string to uppercase.

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

.casefold()

A

Converts the entire string to lowercase.

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

.count()

A

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

.count(value, start, end)

value = required
start = optional, default 0
end = optional, default end of string

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

.encode()

A

Returns an encoded version of the string, using specified encoding.

.encode(encoding=encoding, errors=errors)
encoding = optional, default UTF-8
errors = optional, specifies error handling (i.e. strict, ignore, backslashreplace)

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

.endswith()

A

Returns true if the string ends with the specified value.

.endswith(value, start, end)
value = string
start = optional (default 0)
end = optional (default end of string)

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

.find()

A

Searches the string for a specified value and returns the position of where it was found. Returns -1 if not found.

.find(value, start, end)

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

.format()

A

Formats specified values in a string; replaces placeholders defined with curly brackets.

.format(values)

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

.isalnum()

A

Returns True if all characters in the string are alphanumeric (a-z, 0-9).

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

.isalpha()

A

Returns True if all characters in the string are in the alphabet (a-z).

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

.isascii()

A

Returns True if all characters in the string are ASCII characters (a-z, 0-9, some special chars like $, &, *).

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

.isdecimal()

A

Returns True if all characters in the string are decimals (0-9).

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

.isdigit()

A

Returns True if all characters in the string are digits (0-9).

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

.isidentifier()

A

Returns True if the string is a valid identifier (a-z, 0-9 and _).

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

.islower()

A

Returns True if all characters in the string are lower case.

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

.isnumeric()

A

Returns True if all characters in the string are numeric.

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

.isprintable()

A

Returns True if all characters in the string are printable.

\n is not printable.

17
Q

.isspace()

A

Returns True if all characters in the string are whitespaces.

18
Q

.istitle()

A

Returns True if the string follows the rules of a title (all words start with an upper case letter AND the rest is lowercase).

Symbols and numbers ignored.

19
Q

.isupper()

A

Returns True if all characters in the string are upper case.

20
Q

.join()

A

Converts the elements of an iterable into a string, joined on separator.

separator.join(iterable)
“ “.join([“It’s”, “my”, “birthday”]) –> “It’s my birthday”

21
Q

.lower()

A

Converts a string into lower case.

22
Q

.partition()

A

Returns a tuple with three values based on the FIRST appearance of matched string.

.partition(value)
“I could eat bananas all day”.partition(“bananas”) –> (“I could eat”, “bananas”, “all day”)
If no match found for value, returns (str, ‘’, ‘’).

23
Q

.replace()

A

Returns a string where a specified value is replaced with another specified value.

.replace(oldValue, newValue, count=ALL)

24
Q

.rfind()

A

Returns the last occurrence of value, or -1 if not found.

.rfind(value)

25
.rindex()
Returns the last occurrence of value; raises ValueError if not found. ## Footnote .rindex(value)
26
.rpartition()
Returns a tuple with three values based on the LAST appearance of matched string. ## Footnote .partition(value) "I could eat bananas all day".partition("bananas") --> ("I could eat", "bananas", "all day") If no match found for value, returns ('', '', str).
27
.rsplit()
Splits the string at the specified separator, and returns a list, starting from the right. ## Footnote .rsplti(separator, maxSplit=-1 (ALL))
28
.split()
Splits the string at the specified separator, and returns a list. ## Footnote .split(separator, maxSplit) default = splits on whitespace.
29
.startswith()
Returns true if the string starts with the specified value. ## Footnote .startswith(value, start, end)
30
.strip()
Returns a trimmed version of the string; trailing and leading spaces removed. ## Footnote .strip("str") --> will also remove additional letters.
31
.swapcase()
Swaps cases; lower case --> uppercase AND uppercase --> lowercase.
32
.title()
Converts the first character of each word to upper case, rest to lowercase
33
.upper()
Converts a string into upper case.
34
.zfill()
Fills the string with leading zeroes until it reaches specified length. ## Footnote .default 0 "potato".zfill(8) --> "00potato".