Basic Python Flashcards
(14 cards)
Declare a string
first_name = “Bryan”
Declare an integer variable
age = 21
Declare a float variable
radius = 3.14
Declare a Boolean
is_Large = True
Declare a List
networks = [“social”, “computer”, “television”]
Declare a dictionary
address = {“street”: “Maple Lane”, “house_num”: “101”}
Declare a tuple
languages = (‘Python’, ‘Javascript’)
Declare a set
suits = {“Hearts”, “Clubs”, “Spades”, “Diamonds”}
What are the differences between a list, set, and tuple
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
If x is greater than zero, print “Positive”. Else if x is less than 0 print “Negative”. Else print “Zero”.
if x > 0:
print(“Positive”)
elif x < 0:
print(“Negative”)
else:
print(“Zero”)
For Loop: Print all numbers from 0 to 5 (in range).
for i in range(5):
print(i)
While Loop. Print all numbers from 0 to 5.
count = 0
while count < 5:
print(count)
count += 1
Function. Take name as a parameter and return a string to say “Hello NAME”. Set the default argument to “Bob”.
Then call the function.
def greet(name=”Bob”):
return f”Hello there, {name}!”
greet(“Wayne”)
greet()