Quiz 2 Flashcards

1
Q

What is an f-string? and what’s it used for?

A

Formatted string literal - used to format output of expressions

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

What is a statement

A

programming instruction

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

What is an expression

A

Code that returns a value (eg. calculations)

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

What is an assignment

A

A new variable is assigned

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

What is a string literal

A

Text enclosed in quotations

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

What does an object represent

A

A value (eg. in x=4, 4 is automatically created as an object)

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

What does immutable mean? What is mutability?

A

Immutable means it can’t be changed. Mutability is on object’s ability to be changed.

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

Which data types are mutable

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

Which data types are immutable

A

strings and integers

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

What is a literal?

A

A specific value

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

What is a logical operator/boolean logic?

A

Treats operands as True or False (for example, x>4 -> True).

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

What are the three examples of logical operands?

A

And, or, not

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

What is a while loop (difference between that and a for loop?)

A

Loop that goes until we reach a condition
NEED TO ADD AN ITERATOR (i-0)
Could continue forever (for loop has a range)

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

What is a for loop (difference between that and a while loop?)

A

Loop that has an end
Automatically puts in the iterator
Has a range (while loop could continue forever)

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

what is a modulus (example)

A

%
division with a remainder
ex: 7%2 = 1

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

== vs =

A

== - checking IF something is true (x==5, does x equal 5?)
= - this IS true (ex: x=5)

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

What is a value?

A

Content being stored (types: strings, integers…)

18
Q

What is a float

19
Q

What is an integer?

A

whole number

20
Q

What does // do?

A

how many times the divider can fit in
ex: 5//2 = 2
2 can fit in 5 twice

21
Q

What is pseudocode

A

Explanation in sentences

22
Q

Do you need to add an iterator for a for loop?

A

No! (automatically knows)

23
Q

what happens if we had a break into the loop?

A

It skips the else statement

24
Q

What does n += 1 mean?

25
Q

what is len ( ) used for?

A

finding the length of a string

26
Q

What does a 0 indexed language mean?

A

python starts from 0 when counting (not from 1)

27
Q

What is included in this range? for i in range (0, 5)

A

0, 1, 2, 3, 4

28
Q

what does the escape sequence \n do? ex: print(“My name…\nIs John..”)

A

makes a newline
Ex: My name…
Is John..

29
Q

What does the escape sequence \t do? ex: print(“1. Bake cookies\n\t1.1. Preheat oven”)

A

Tab (indent)
1. Bake cookies
(tabed)1.1. Preheat oven

30
Q

What is a raw string?
ex what will this print out?: raw_sequence = r’ Hello, my name is \n Lydia’
print(“raw_sequence”)

A

when escape sequences are ignored
ex: Hello, my name is \n Lydia

31
Q

What does the escape sequence \ do?
ex what will this print out?: print(“\home\users\”)

A

prints a \
ex: \home\users\

32
Q

What does the escape sequence ' do?
ex what will this print out?: print(“Name: John O'Donald”)

A

prints a single quote ‘
Name: John O’Donald

33
Q

What does the escape sequence " do?
ex what will this print out?: print(“He said, "Hello friend!"”)

A

prints a double quote “
He said, “Hello friend!”

34
Q

What does ord ( ) do?

A

returns encoded integer value for a string of length one
ex: ord(‘A’) = 65

35
Q

What does chr( ) do?

A

returns a string of one character for an encoded integer
ex: chr(‘65’) = A

36
Q

What are the 4 types of f-strings (that we’re using)?

A

d - Decimal (for integer values only)
e - Exponent notation
f - Fixed point notation
s - string (default presentation type)

37
Q

What is :d specification
What will this print?
ex: number = 4
print(f’ {number:d} ‘ )

A

d - Decimal (integer values only)
will print: 4

38
Q

What is :e specification
what will this print?
ex: number = 44
print(f’ {number:e} ‘ )

A

e - exponent notation
will print: 4.400000e+01

39
Q

What is :f specification
what will this print?
ex: number = 4
print(f’ {number:f} ‘ )

A

f - fixed-point notation
will print: 4.000000

41
Q

What is in an advanced f-string?
(f”{Expression:[fill][Align][Sign][Width][.Precision][type]}

A

my_num = 123.987
ex: (f”{my_num:+08.2f}”)
print: +0123.99
fill - 0’s or white spaces
align - sign to know where the answer goes (don’t worry about this as much)
sign - adding a +/- in front
width - how many spots there are (ex: 8)
.Precision - how many decimals
type - f, s, d, e

42
Q

What does print( ) do?

A

Prints a newline (same as \n)