Week 1 - Intro to Python, Variables, Built-in Functions, Number Types Flashcards

1
Q

Which will perform the intended function?
if 5 > 2:
l print(“Five is greater than two!”)

OR

if 5 > 2:
print(“Five is greater than two!”)

A

The first line of code, as the indentation indicates to python that the print() line is part of the if statement. (indentation matters!)

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

If you execute the code (in a google copilot text cell):
4+6
1+2
which will be returned?

A

3

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

what is the result of:

> > > 2e3

A

2000.0

remember, e always creates a float value!

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

how would you make an expression over multiple lines?

A

use either \ OR ()
»>45 + 39 \
… -3

> > > 45 + 93 \
-4

> > > (4293 + 0394923948
+323)

all work!

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

what happens if you name a variable a function name (i.e. print = 4)

A

the variable will work, but the function will be unusable until you delete the variable using “»> del print”

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

does this work?
x, y = 2, 3

A

yes

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

how does the round function work?

A

it rounds up or down unless the decimal is 0.5, in which it rounds up if the whole number is odd, and down when the whole number is even.

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

x = 5
y = 12

what will
print(x, y)
result in? what about
x, y
?

A

print will give you
5 12
nonprint will give you
(5, 12)
^creates an object (not in scope of lesson 1)

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

what happens when a function isnt returning anything, but are run?

A

functions like print actually return the value “None”

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

what does the type() function do?

A

returns the types of variables (which are actually objects created from classes)
type shows the type, or CLASS, of a variable, or OBJECT
print(type(x))
<class ‘int’>

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

what are the types of numbers in Python?

A

int, float, and complex (a + bj or a + bJ)

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

print(type(3)) VS type(3)

A

<class ‘int’>

vs

int

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

addition, subtraction, multiplication, negation, and exponentiation

A

*
-
**

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

float division, integer division, remainder division

A

float = /, always results in float
integer = //, results in float only if float as numerators/denominators, but CONCEPTUALLY DIVIDES INTO INTEGER (4.5//2 = 2.0)
remainder = modulus = % = remainder left over (could be either float or int)

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

round 2/3 to 3 decimal places

A

round(2/3, 3)

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