Unit 5: Strings Flashcards

1
Q

What is the purpose of string slicing ?

A

read more than one character at a time. Multiple consecutive characters can be read using slice notation.

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

Slice notation syntax

A

my_str[start:end]

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

Determines how much to increment the index after reading each element

A

Stride

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

Stride syntax in slice notation

A

my_str[start:end:stride]

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

format specification that defines the minimum number of characters that must be inserted into the string. If the replacement value is smaller in size than the given field width, then the string is padded with space characters.

A

Field width

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

Field width syntax

A

{name:16}

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

character that determines how a value should be aligned within the width of the field.

A

Alignment character

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

alignment character format

A

{name:>16}

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

is used to pad a replacement field when the inserted string is smaller than the field width. The default character is an empty space ‘ ‘

A

Fill character

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

fill character syntax

A

{name:0>16}

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

floating point precision

A

format specification indicates how many digits should be included in the output of floating types.

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

floating point precision syntax

A

{name:0>16.2f}
{variable_name:.2f}

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

replace(old, new)

A

Returns a copy of the string with all occurrences of the substring old replaced by the string new. The old and new arguments may be string variables or string literals.

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

replace(old, new, count)

A

Same as above, except replace(old, new, count) only replaces the first count occurrences of old.

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

find(x)

A

find(x) – Returns the index of the first occurrence of item x in the string, otherwise, find(x) returns -1. x may be a string variable or string literal

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

find(x, start)

A

Same as find(x), but begins the search at index start

17
Q

find(x, start, end)

A

Same as find(x, start), but stops the search at index end - 1

18
Q

rfind(x)

A

Same as find(x) but searches the string in reverse, returning the last occurrence in the string.

19
Q

count(x)

A

Returns the number of times x occurs in the string

20
Q

syntax for positional string methods

A

my_str.method()

21
Q

Methods to check a string value that returns a True or False Boolean value:

A

isalnum() – Returns True if all characters in the string are lowercase or uppercase letters, or the numbers 0-9.
isdigit() – Returns True if all characters are the numbers 0-9.
islower() – Returns True if all cased characters are lowercase letters.
isupper() – Returns True if all cased characters are uppercase letters.
isspace() – Returns True if all characters are whitespace.
startswith(x) – Returns True if the string starts with x.
endswith(x) – Returns True if the string ends with x.

22
Q

Methods to create new strings

A

capitalize() – Returns a copy of the string with the first character capitalized and the rest lowercased.
lower() – Returns a copy of the string with all characters lowercased.
upper() – Returns a copy of the string with all characters uppercased.
strip() – Returns a copy of the string with leading and trailing whitespace removed.
title() – Returns a copy of the string as a title, with first letters of words capitalized.

22
Q

Methods to create new strings

A

capitalize() – Returns a copy of the string with the first character capitalized and the rest lowercased.
lower() – Returns a copy of the string with all characters lowercased.
upper() – Returns a copy of the string with all characters uppercased.
strip() – Returns a copy of the string with leading and trailing whitespace removed.
title() – Returns a copy of the string as a title, with first letters of words capitalized.

23
Q

split() method

A

The string method split() splits a string into a list of tokens. Each token is a substring that forms a part of a larger string. A separator is a character or sequence of characters that indicates where to split the string into tokens

24
Q

split method syntax

A

my_str.split(‘seperator’)

25
Q

join() method

A

string method performs the inverse operation of split() by joining a list of strings together to create a single string.

26
Q

join() method syntax

A

my_str = ‘seperator’.join(my_token)