String Methods Flashcards

1
Q

.capitalize()

A

(string method)

Converts the first character to upper case

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

.casefold()

A

(string method)

Converts all the uppercase letters in a string to lowercase letters

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

.count(substr)

A

(string method)

counts the number of times the substr appears in string

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

.endswith(substr)

A

(string method)

Returns true if the string ends with the substr, else False

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

.find(substr)

A

(string method)

Returns the index of the first occurence of the substr in the string

Returns -1 if substr not found in string

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

.format()

example

“My name is {}, I’m {}”.format(“John”,36)

“My name is {0}, I’m {1}”.format(“John”,36)

“My name is {fname}, I’m {age}”.format(fname = “John”, age = 36)

A

(string method)

The format() method formats the specified value(s) and insert them inside the string’s placeholder.

The placeholder is defined using curly brackets: {}

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

.index(substr)

A

(string method)

returns the index of the specified substr in the str

raises an exception if the value is not found

(very similar to .find(), but .find() return -1 when the substr is not found)

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

.isalnum()

A

(string method)

returns True if all characters are alphanumeric

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

.isalpha()

A

(string method)

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

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

.isascii()

A

(string method)

Returns True if all characters in the string are ascii characters

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

.isdigit()

A

(string method)

Returns True if all characters in the string are digits

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

.lower()

A

(string method)

Returns the lowercased value of the input string

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

.replace(old, new, count)

A

(string method)

returns a copy of the string where the old substring is replaced with the new string

params
1. old = value to replace
2. new = what to replace it with
3. (optional) # of instances (defaults to replacing ALL)

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

.upper()

A

(string method)

method returns a string where all characters are in upper case.

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

.strip()

A

(string method)

Returns a trimmed version of the string (no trailing or leading spaces)

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

len(str)

A

(built-in)

returns length of the string

17
Q

.title()

A

(string method)

Returns the string in title case

18
Q

.split(separator)

A

(string method)

splits a string into a list, returns that list

you can specify a separator, or the separator is whitespace