Chapter 6 escape characters Flashcards

1
Q

What are escape characters?

A

Escape characters represent characters in string values that would otherwise be
difficult or impossible to type into code.

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

What do the \n and \t escape characters represent?

A

\n is a newline; \t is a tab.

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

How can you put a \ backslash character in a string?

A

The \ escape character will represent a backslash character.

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

The string value “Howl’s Moving Castle” is a valid string. Why isn’t it a problem that the single quote
character in the word Howl’s isn’t escaped?

A

The single quote in Howl’s is fine because you’ve used double quotes to mark the
beginning and end of the string.

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

If you don’t want to put \n in your string, how can you write a string with newlines in it?

A

Multiline strings allow you to use newlines in strings without the \n escape
character.

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

What do the following expressions evaluate to?

‘Hello world!’[1] ‘Hello world!’[0:5] ‘Hello world!’[:5] ‘Hello world!’[3:]

A

The expressions evaluate to the following:

‘e’ ‘Hello’ ‘Hello’ ‘lo world!

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

What do the following expressions evaluate to?

‘Hello’.upper() ‘Hello’.upper().isupper() ‘Hello’.upper().lower()

A

The expressions evaluate to the following:

‘HELLO’ True ‘hello’

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

What do the following expressions evaluate to?

‘Remember, remember, the fifth of November.’.split() ‘-‘.join(‘There can be only one.’.split())

A

The expressions evaluate to the following:

[‘Remember,’, ‘remember,’, ‘the’, ‘fifth’, ‘of’, ‘November.’] ‘There-can-be-only-one.’

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

What string methods can you use to right-justify, left-justify, and center a string?

A

The rjust(), ljust(), and center() string methods, respectively

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

How can you trim whitespace characters from the beginning or end of a string?

A
The	lstrip()	and	rstrip()	methods	remove	whitespace	from	the	left	and	right
ends	of	a	string,	respectively.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly