Strings Flashcards

functions and methods for string Manipulation

1
Q

string.ascii_letters

A

A constant, all the ASCII letters:
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

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

string.ascii_lowercase

A

A constant, all the lowercase ASCII letters:
"abcdefghijklmnopqrstuvwxyz"

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

string.ascii_uppercase

A

A constant, all the uppercase ASCII letters:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"

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

string.digits

A

A constant, the digits:
"0123456789"

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

string.hexdigits

A

A constant, the digits plus uppercase and lowercase letters a-f for hexadecimal:
"0123456789abcdefABCDEF"

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

string.octdigits

A

A constant. The digits for octal:
"01234567"

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

string.printable

A

A constant string. All the ASCII symbols considered printable. Letters, numbers, grammer, whitespace.

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

string.punctuation

A

A constant. Punctuation symbols

"%&'()*+,-./:;<=>?@[\]^_\`{|}~"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

string.whitespace

A

A constant. All the whitespace characters: Space, tab, linefeed, return, formfeed, vertical tab

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

textwrap.fill(my_paragraph, 50)

A

Adds newline characters to my_paragraph such that each line is no more than 50. This left aligns the text

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

textwrap.dedent(my_paragraph)

A

Remove any leading whitespace common to all lines in my_paragraph

textwrap.dedent("\t\t hello\n\t world)
>>> "\t hello\n world"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

textwrap.indent(my_text, "\t")

A

Indent all lines in my_text with \t

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

textwrap.indent(my_text, "\t", lambda line: "cats" in line)

A

indent all lines with “\t” in my_text which contain the string "cats"

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

textwrap.shorten(“Hello world, my name is Philip”, 12)

A

"hello [...]" shortens the text to width 12. Adds in [...] placeholder to indicate it is shortened. Can use a custom placeholder with the placeholder argument.

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

re.search(my_regex, my_text)

A

Finds the first occurrance of the pattern specified in my_regex in my_text. Returns None when no match is present, or a re.Match object when there is a match.

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