What is a boolean?
A Python data type that represents if a statement is True or False.
You type this to tell Python that you are creating a function.
def
This is the operator used to concatenate.
+ (addition operator)
4**2/4 is equal to this number.
4
What is a python data type that represents whole numbers.
Integer (int, ex: 4, 12, 3)
What boolean operator do we use to check if one value is not equal to another value?
!= (not equal to)
Name 2 methods that can mutate a list
insert, append, del
What will be displayed on the console:
print("Hello! ")
#print("Nice to meet you!)
Hello!
#print("Nice to meet you!) is a line of comment (# symbol is for comment) that won't be executed by Python.
What will be returned when the code finishes running?
def fun(a)
if a > 30:
return 5
else
return 10 + fun(a + 5)
fun(10)
What is a base case in recursion?
It is the condition in which the recursive function will stop executing.
What is the difference between "and" and "or" in python?
"and" only returns True when BOTH statements are True.
"or" returns True if one or more statement is true and False if both statements are false
What is wrong with the following code:
num = input("Please enter your num: ")
It should be num = int(input("Please enter your num: "))
What is the difference between // and /?
// - integer division
/ - decimal division
What is the result of the following code: print((6**2 - 4 * 2) % 5)
3
What are the naming conventions we use in python?
camelCase and under_scores
Name at least 4 comparison operators you can use in an if statement. One example: ==
==, <, >, !=, <=, >=
What will be displayed on the console:
def sayHello (name):
return("Hello, " + name)
sayHello("Macy")
Nothing.
The function sayHello is returning, but not printing. If you want to print the value returned by the function sayHello on the console, you should type:
print(sayHello("Macy"))
What symbol do you use to computer remainder?
% (the modulus symbol)
What will be the output of the following block of code:
count = 1
while (count < 5):
print("Nice to meet you!")
count = count + 1
Nice to meet you!
Nice to meet you!
Nice to meet you!
Nice to meet you!
What operator has the highest precedence in python?
( ) parenthesis
What is the result:
x = 12
y = 12.0
print(("apple" == "Apple" or x < 10) and x == y)
False
What is wrong with the following header of a function in Python:
def functionOne arg1, arg2, arg3
There should be parathesis surrounding the parameters, and there should be colon at the end.
It should be:
def functionOne (arg1, arg2, arg3):
What symbols are used to create a list?
[ ] (brackets)
What is wrong with the following block of code:
i = 10
while (i > 5):
print("Hi!")
i = i + 1
This results in an infinite loop. Since i starts from 10 and we are increasing the value of i using i = i + 1, this will make the condition i > 5 always True (there will never be a moment when i is less than or equal to 5), which results in an infinite loop.
What is the difference between parameter and argument in Python function?
A parameter is the variables listed in the header. An argument is the real value passed to the function when the function is called.