Topic 7 - Sequence Types Flashcards

1
Q

In the following code example, what is the backslash doing?

variable = “She said, "Hello!"”

A

The backslash is being used as an escape character. This will allow the double quotes to be printed.

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

What escape character is used to enter a tab?

A

\t

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

How can you stop python from interpreting escape characters?

A

Though the use of raw strings.

A string will need the ‘r’ prefix.

Example:

string = r’line1\nline2’

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

Using a print statement, how would you print a straight line?

A

print(‘_’ * 40)

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

What functions is used to find the length of a string?

A

len

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