Strings & Variables Flashcards

(13 cards)

1
Q

What should you do if you want to use /output text in Python?

A

you have to use a string.

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

How is a string created?

A

A string is created by entering text between two single or double quotation marks.

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

What would I call what is inside the quotation marks?

print( ‘Coding in Finance’)
print (“An investment in knowledge pays the best interest.”)

A

A string

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

For characters that can’t be directly included in a string. For instance, double quotes can’t be directly included in a double quote string; this would cause it to end prematurely.

What is used?

A

Characters like these must be escaped by placing a backslash before them.

E.g
print( ‘Brian\’s mother: He\’s not an angel. He\’s a very naughty boy!’)

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

What represents a new line in Python?

A

\n represents a new line.

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

Which of the following options results in exactly two lines?

‘one ' two ' three’
“Hello \n world”
“Hello world”
“Some \n text \n goes here”

A

“Hello \n world”

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

How can you make newlines automatically be added?

A

Newlines will be automatically added for strings that are created using three quotes.

E.g:
print(““this
is a
multiline
text”””)

Output:
this
is a
multiline
text

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

What is concatenation?

A

As with integers and floats, strings in Python can be added.

E.g:
print (“Spam”+ ‘eggs’)

Output:
Spameggs

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

If your strings contain numbers, how are they added?

A

Even if your strings contain numbers, they are still added as strings rather than integers.

E.g:
print (“2”+”2”)

Output:
22

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

What happens of you add a string and a number?

A

Adding a string to a number produces an error, as even though they might look similar, they are two different entities.

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

What happens if you multiply strings by integers?

A

Strings can also be multiplied by integers. This produces a repeated version of the original string.

E.g:
print (“spam” * 3)
print (4 * ‘2’)

Output:
spamspamspam
2222

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

Can strings be multiplied by other strings?

A

Strings can’t be multiplied by other strings.

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

Can strings be multiplied by floats?

A

Strings also can’t be multiplied by floats, even if the floats are whole numbers.

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