String Operatons Flashcards

1
Q

How does the ‘+’ operator work when used with strings?

A

The ‘+’ operator will concatenate two or more strings into a single string.

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

How does the replace() method work?

A

this method takes two arguments, it then replaces all instances of the first argument with the second argument. Note this is a substring method.

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

How does the find() method work?

A

This method takes a string as an argument it then searches the string it was called on and returns the first index value where that substring is located.

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

How does the .format() method work?

A

This method can be used to interpolate variables into a string. Use a ‘f-string’ instead!

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

How does the basic split() method with no argumets work?

A

The split() method returns a list of substrings that has been split by a delimiter. If no argument is passed to the method the default delimiter is the “ “ space character.

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

How does the split method work with a delimiter as an argument?

A

Note that the delimiter must be passed as a string. The delimiter is not included in the list of substrings, the method returns a empty string if the string ends with the delimiter.

print(greatest_guitarist.split(‘a’))
output: [’s’, ‘nt’, ‘n’, ‘’”]

Note you can also split based on escape characters such as \n “newline” and \t “horizontal tab”

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

How does the join() method work?

A

The join() method is the opposite of the split() method. It uses a delimiter to join a list of strings.

‘delimiter’.join(list_you_want_to_join)

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

How do we create a csv from a list?

A

CSV stands for “Comma-Separated Values.” It is a simple and widely used file format for storing tabular data, such as spreadsheets or databases.

call the join() method on a “ ,” with a list of strings as the argument.

”,”.join(my_list_of_strings)

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

How does the strip() method work?

A

The strip() method with no arguments when called on a string removes white space from the start and end of the string. The method can also be called with a specific character which will be stripped from the start and end of the string.

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

Strings are immutable, what does this mean?

A

This means a string once created cannot be changed. Operations performed on strings such as slicing and concatenation create a new string.

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

What are the three main string methods that can change the case of a string?

A

‘.lower()’
‘.upper()’
‘.title()’
remember that strings are immutable so the result is a new string. The original string does not change.

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