String Methods Flashcards

1
Q

Give an example of Python code that employs a string method

A

x=”yesss”
x.islower()
this would return True because “yesss” is all lowercase
can also do “yesss”.islower()

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

Returns True if the string contains only alphabetic letters or digits and is at least one character in length. Returns False otherwise.

A

isalnum()

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

Return True if the string contains only alphabetic letters and is at least one character in length. Returns False otherwise.

A

isalpha()

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

Returns True if the string contains only numeric digits and is at least one character in length. Returns False otherwise.

A

isdigit()

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

Returns True if all the string contains only numeric digits and is at least one character in length. Returns False otherwise.

A

isdigit()

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

Returns True if all of the alphabetic letters in the string are lowercase, and the string contains at least one alphabetic letter. Returns False otherwise.

A

islower()

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

Returns True if the string contains only whitespace characters and is at least one character in length. Returns False otherwise. (Whitespace characters are spaces, newlines \n, and tabs \t)

A

isspace()

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

Returns True if all of the alphabetic letters in the string are uppercase, and the string contains at least one alphabetic letter. Returns False otherwise.

A

isupper()

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

Returns a copy of the string with all alphabetic letters converted to lowercase. Any character that is already lowercase, or is not an alphabetic letter, is unchanged.

A

lower()

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

Returns a copy of the string with all leading whitespace characters removed. Leading whitespace characters are spaces, newlines (\n), and tabs (\t) that appear at the beginning of the string.

A

lstrip()

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

The char argument is a string containing a character. Returns a copy of the string with all instances of char that appear at the beginning of the string removed.

A

lstrip(char)

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

Returns a copy of the string with all trailing whitespace characters removed. Trailing whitespace characters are spaces, newlines (\n), and tabs (\t) that appear at the end of the string.

A

rstrip()

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

The char argument is a string containing a character. The method returns a copy of the string with all instances of char that appear at the end of the string removed.

A

rstrip(char)

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

Returns a copy of the string with all leading and trailing whitespace characters removed.

A

strip()

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

Returns a copy of the string with all instances of char that appear at the beginning and the end of the string removed.

A

strip(char)

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

Checks if the string ends with substring (returns True or False)

A

endswith(substring)

17
Q

Checks if the string starts with substring (returns True or False)

A

startswith(substring)

18
Q

Searches for substring within the string (returns lowest index of the substring or -1 if not found)

A

find(substring)

19
Q

Returns a copy of the string where every occurrence of substring is replaced with new_string

A

replace(substring, new_string)

20
Q

Changes a string into a list of strings

Separates the content of a string based on where spaces are found (by default)

A

split()