U of W Bits Flashcards

1
Q

log something

A

print(‘something’)

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

make a variable

A

variable = 123

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

get the type of something

A

type(‘thing’) # string

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

make a comment

A

number sign
> #this is a comment

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

What are the types in python?
what do we call arrays and objects in python?

A

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType

object = dictionary
array = list

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

convert types

A

str(123)
float(123) #123.0
int(123.7) #123 (just removes the decimal)

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

get input

A

input()

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

get the length of a string

A

len(‘123’) #3

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

what happens with this with this if you input a number like 32?
if input() > 10:
print(‘yes’)

A

error. It does not implicitly convert
have to do:
if int(input()) > 0:
print(‘yes’)

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

slice a bit of a string

A

‘01234’[0:2] # ‘01’

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

concatenate a string

A

‘01’ + ‘23’ # ‘0123’

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

Difference between:

result = ‘one’ + 2
print(result)

and

result = 1 + ‘two’
print(result)

A

both will fail. have to explicitly convert

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

repeat a string

A

‘two’ * 3 # ‘twotwotwo’

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

initiate a loop (while loop)

A

counter = 0

while counter < 10:
print(‘hello’)
counter = counter + 1

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

initiate a loop with the conditions applied (for loop)

A

1 for counter in range(10, 15):
2 print(“counter is”, counter)

counter is 10
counter is 11
counter is 12
counter is 13
counter is 14

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

stop a loop
skip this iteration of the loop

A

break
continue

16
Q

declare a function

A

def my_function():
print(“Hello from a function”)

17
Q

Do an else and else if statement

A

if x > 0:
code
else x < 0:
code
elif:
code

18
Q

do and or and not

A

and
or
not

just the words

19
Q

What happens with this:
def square(x):
return x*x
print(square(7, 11))

A

error
too many arguments. same with too few

20
Q

define a list
access an element

A

apple = [0, 1, 2]

print(apple[1])

21
Q

get the length of a list

A

len([1, 2]) #2

22
Q

concatenate a list

A

[1, 2] + [1, 2] # [1, 2, 1, 2]

23
Q

duplicate list elements

A

[1, 2] * 3 # [1, 2, 1, 2, 1, 2]

24
Q

get the max value in a list
sum the list

A

print(sum(list))
print(max(list))

25
Q

loop over a list (using built in for loop)

A

apple = [0] * 20

for x in apple:
print(x)

26
Q

loop over a string (using built in for loop)

A

for x in ‘apple’:
print(x)