Week 6 - Python Flashcards
How to run a Python program?
python programName.py
What are some of biggest differences between Python and C that make Python way cleaner?
- No semicolons at the end of lines
- No curly braces on blocks
- No parenthesis on conditionals
- No type mentioning on vars. declarations/initilializations
How to declare a function on Python?
def functionName()
What should always be the very last line of code of any Python program?
Main call - main()
What’s the downside of Python being so much easier to program than C, i.e.?
Expense of performance, because of so many functions running in the background
What’s the comments markup in C?
#
What are the loops that can be used in Python?
While loops and for loops
What are lists in Python?
Arrays
What’s the biggest advantage of Python’s lists?
They’re not size fixed
What’s the lists markup on Python?
Square brackets
What are tuples?
They’re a data type in Python similar to C’s structs, but they have inmutable values
What are objects in Python?
They’re similar to C structs
Why styling is even more important in Python?
Because if tabs and indentation are not used things may not work as intended
import fileName in Python is the equivalent to what in C?
include <file_name></file_name>
What should be used instead of || and && operators in Python?
Or/and
What should be used instead of else if in Python?
elif
What to use instead of the bang operator (!) in Python?
The keyword not
How to write the increment by one operator in Python?
+= 1
Write a range function
for x in range(100):
print(x)
What does the range function do?
Iterates until the stop condition passed as an argument - 1
What are dictionaries?
Dictionaires are like hash tables in C. They have key-value pairs
What’s the markup for dictionaires in Python?
Curly braces
What are methods?
Functions that can only be called on objects
How to add keys and values to dictionaries?
book[“title”] = “Corduroy”
How are libraries called in Python?
Modules
What’s the advantage of using with open(“fileName.ext”) as file?
Not having to close the file, because Python will do it automatically