Basic Python Flashcards

(14 cards)

1
Q

Declare a string

A

first_name = “Bryan”

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

Declare an integer variable

A

age = 21

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

Declare a float variable

A

radius = 3.14

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

Declare a Boolean

A

is_Large = True

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

Declare a List

A

networks = [“social”, “computer”, “television”]

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

Declare a dictionary

A

address = {“street”: “Maple Lane”, “house_num”: “101”}

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

Declare a tuple

A

languages = (‘Python’, ‘Javascript’)

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

Declare a set

A

suits = {“Hearts”, “Clubs”, “Spades”, “Diamonds”}

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

What are the differences between a list, set, and tuple

A

Lists: are ordered, mutable, and can contain duplicate values

Sets: are unordered, mutable, and contain unique values

Tuples: are ordered, immutable, and can contain duplicate values

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

If x is greater than zero, print “Positive”. Else if x is less than 0 print “Negative”. Else print “Zero”.

A

if x > 0:
print(“Positive”)
elif x < 0:
print(“Negative”)
else:
print(“Zero”)

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

For Loop: Print all numbers from 0 to 5 (in range).

A

for i in range(5):
print(i)

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

While Loop. Print all numbers from 0 to 5.

A

count = 0
while count < 5:
print(count)
count += 1

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

Function. Take name as a parameter and return a string to say “Hello NAME”. Set the default argument to “Bob”.

Then call the function.

A

def greet(name=”Bob”):
return f”Hello there, {name}!”

greet(“Wayne”)
greet()

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