What does += do?
Adds a value to a variable and assigns its new value.
Is "2var" a legal variable name?
No, variables cannot start with a number
What is wrong with the following code:
print(I love Coding Academy)
The print function needs quotations around the string.
print("I love Coding Academy")
What function is used to find the length of a list?
len()
How do you create/establish a function?
You define it using def().
What are nested loops?
A loop inside of a loop.
What are the two (technically three) types of variables?
Strings and Integers (and Float)
What is wrong with the following code:
thislist = ("red", "yellow", "green")
Lists need brackets instead of parentheses.
thislist=["red", "yellow", "green"]
Why would someone use a list?
To store multiple items in a variable.
What are if/else statements called?
Conditionals
What is used to fix a for loop to run for a specific amount of times?
range()
What does the != operator mean?
Not Equal
What will the following code display:
for x in range(5, 30, 6):
print(x)
5, 11, 17, 23, 29
When creating lists, what do you need to add to strings but not integers or Booleans?
Quotes
Describe what a function is and why we use them.
A function is a chunk of code that runs when it is called. Using functions can refine and organize code by establishing what each chunk of code does.
In a range function, what does each number represent in range( 6, 30, 5)?
range(min, max, increment value)
What does case sensitive and does it apply to variables?
Case sensitive means to be specific about upper/lower case. This applies to variables.
What will the following code do:
fruits = ["apple", "oranges", "cherries"]
fruits.pop(1)
print(fruits)
It will print the list without oranges.
How do you add an item to the end of a list?
Use the append() function
Ex.
thislist.append("orange")
How do you make comments in Python?
You use the # symbol.
What is the difference between for loops and while loops?
While loops execute while a condition is true, while for loops executes through a sequence (no condition needs to be met).
What type of values can variables hold?
Strings, Integers, and Floats
What will the following code do:
i = 1
while i < 11:
print(i)
i += 1
It would print the integers 1-10.
How is the append function and the insert function different?
The append function adds to the very end of the function while the insert function can insert an item anywhere on a list.
What is type casting?
The conversion of strings to integers or integers to strings.