01 Comments, Variables, Console Flashcards
True or False: Python program code is executed line by line, from first to last line.
True
True or False: Every line of code, no matter what kind, is always evaluated left to right.
False
Expressions are evaluated left to right but assignments are evaluated right to left.
What expression/s are equivalent to this expression: a * b * c
- a * (b * c)
- b * a * c
- (a * b) * c
- c * b * a
- (a * b * c)
2, 3 and 5 are equivalent.
What expression/s are equivalent to this expression: a = b * c
- a = (b * c)
- b = a * c
- a = c * b
- c * b = a
- b * c = a
1 and 3 are equivalent
When it comes to coding styles, Python will…
- force you to follow a certain style.
- not force you to follow a certain style but there are recommentations.
- not force you to follow a certain style and there aren’t any recommendations either.
- not force you to follow a certain style but there are recommentations.
Why should programmers adhere to coding conventions and style recommendations?
- easier maintainability
- more consistency
- easier understanding of someone else’s code
For what parts are there style recommendations?
- naming converntions
- comment styles
- formatting
What are comments and how are they indicated?
- comments will not be executed
- used for documentation purposes
- indicated by putting a # at the start of the comment
- the # doesn’t have to be at the beginning of the line, the comment can start anywhere in a line
- everything after the # will not be considered code and has no effect on the program
What are the main data types used in this semester?
- bool
- int
- float
- str
Choose the correct statement/s.
- a boolean data type can only store the values True and False.
- if I put the string “true” in a boolean data type, it works because Python is smart enough to automatically convert it into the value True.
- instead of True and False, I can also store the numbers 0 and 1.
- when creating a boolean variable, I always have to specify tell Python that the data type should be boolean.
- is correct
- is false. If you put a string into a boolean variable, it automatically becomes a string variable
- is false. If you put a number into a boolean variable, it automatically becomes a int/float variable. However, the boolean values True/False can be output in form of 0 or 1.
- is false. When creating a variable no data type is specified. Python assigns the data type according to the value that’s stored in the variable. Type Hints can be specified but they are only hints and aren’t enforced.
Choose the correct statement/s.
- Float numbers can easily be casted to the int data type without losing any information.
- If an int number is divided, it’s automatically transformed into a float number.
- Float numbers never have more than six decimal places.
- Float numbers are automatically rounded to the nearest integer when cast to an int data type.
- Int numbers can easily be casted to the float data type without losing any information.
- is false. If a float number is cast to the int data type, it loses its decimal information.
- is true.
- is false. They can practially have an infinite amout of decimal places.
- is false. They lose the decimal information and only the integer value is stored in the int data type.
- is true
Choose the correct statement/s.
- A string value can be created using either ‘ or “.
- You can use all basic mathematical operators on strings.
- “3” + “6” equivalents to “36”.
- “3” + “6” equivalents to “9”.
- Any boolean, int or float data type can easily be cast to a string without losing information.
- is true.
- is false. Only “+” and “*” can be used on strings.
- is true.
- is false. The two strings are only ‘pressed’ together, not added.
- is true.
Which of the following statements are true for static typing and which are true for dynamic typing?
- Data type of variable is known at run time.
- Data type of variable itself is specified.
- Used by Java, among other languages.
- Example: x = 5
- Dynamic typing
- Static typing
- Static typing
- Dynamic typing
What happens in Python when a value is assigned to a variable that doesn’t exist yet?
the variable is created and the value is assigned to it
True or False: Variable names are case sensitive.
True