u01-slides-python Flashcards
What is the standard filename suffix for Python files?
.py
What version of Python is recommended in the course?
Version ≥ 3.11
In what order is Python code executed?
Line by line from first line to last line
How are expressions evaluated in Python?
From left to right (e.g. a + b + c is equivalent to (a + b) + c)
How are assignments evaluated in Python?
From right to left (e.g. x = a + b is equivalent to x = (a + (b)))
What character is used to start a comment in Python?
The hashtag character (#)
What is the purpose of comments in Python code?
To document code - they are not executed and have no effect on program behavior
What are the main data types covered in the course?
bool (Boolean), int (Integer), float (Float), str (String)
What values can a Boolean data type store?
Only two values: False (0) or True (1)
What is special about integers in Python?
They are not limited by fixed size (e.g. 32 bits) but are variable-length objects of arbitrary size
What is the range for double-precision floats in Python?
Between approximately ±2.2 × 10^-308 and ±1.8 × 10^308
What is dynamic typing in Python?
The data type is determined during run time and is associated with the value itself not the variable
What are variables in Python?
References or names that are bound to objects - they don’t store information themselves
What are the rules for variable names in Python?
Must start with non-digits/non-operators, are case sensitive, conventionally lowercase with underscores
How do you get user input from the console in Python?
Using the input() function
What is the data type of console input in Python?
String (str) - data type conversion must be done manually if needed
What happens when you assign a variable to another variable in Python?
Both variables reference the same object in memory
What happens when you reassign a value to a variable in Python?
It creates a new reference to a new object - it doesn’t modify the original object
Where can you find Python style recommendations?
https://www.python.org/dev/peps/pep-0008/
What is the conventional format for variable names in Python?
Lower case with words separated by underscores (e.g.
How do you print output to the console in Python?
Using the print() function
Why is code style important in Python?
It helps achieve maintainability, consistency, and helps other programmers understand the code
What is an object in Python?
Everything in Python is an object
What are some examples of reserved keywords in Python?
if, while, for, def, class