Strings and Variables Flashcards

1
Q

”, ‘

A

Used to create a string
ex: “Hello”, ‘345’

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

\

A

Used to escape “ and ‘ when appropriate
ex: print(‘I/’m a cat’) –> I’m a cat

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

\n

A

Creates new line
ex: print(“Hello\nthere”) –>
Hello
there

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

\t

A

Creates tab
ex: print(“Hello\tthere”) –>
Hello there

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

”””

A

Automatically puts newlines when used in place of “ or ‘
ex: print(“"”Why,
hello there”””) –>
Why,
Hello there

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

Concatenation

A

Adding strings together
ex: print(“Spam” + “Eggs”) –> SpamEggs, print(“1”+”2”+”3”) –> 123

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

Strings can be multiplied by floats

A

False, only integers

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

=

A

Creates variable
ex: name = “Anna”

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

Python is a case sensitive languauge

A

True

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

What can be used as a name in Python?

A

Allowed: Letters, Numbers, Underscores
ex: this_is_a_normal_name = 7

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

You can start a name with a number

A

False
ex: 123abc = 7 –> “SyntaxError: invalid syntax”

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

You can reassign a variable as much as you want

A

True, though not good practice

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

input()

A

Function to get input from user
ex: x = input()

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

Even if the user enters a number as input, it is processed as a string.

A

True

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

input(“ “), input(‘ ‘)

A

Creates prompt message
ex: name = input(“Enter your name: “)

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

int()

A

Converts input/variable to an integer
ex: age = int(input())

17
Q

str()

A

Converts input/variable to a string
ex: print(“you are now” + str(age))

18
Q

float()

A

Converts input/variable to a float
ex: money = float(input())

19
Q

+=, -=, *=, /=, %=, etc.

A

In-place operators. Allow you to write code like x= x+3 more concisely
ex: x += 3

20
Q

:=

A

Walrus operator, allows you to assign values to variables within an expression, including variables that do not exist yet.
ex: num = int(input())
print(num) –>
print(num:=int(input()))