oBJECtIVE ASSESSmEnt
PrACtICE EXAm QUEStIonS WIth
CorrECt DEtAILED AnSWErS |
ALrEADy GrADED A+<rECEnt
VErSIon>
1) How can multiple Python variables of different types be output using the print()
function? - ANSWER By separating each variable with a comma
2) What is the scope of a variable that is defined inside a function in Python? -
ANSWER Local Scope
3) How can a global variable be created inside a function in Python? - ANSWER By
declaring the variable with the 'global' keyword
4) What is a characteristic of Python as a dynamically-typed language? - ANSWER
The interpreter determines the type of variable during runtime
5) Which Python data type represents an ordered, mutable sequence? - ANSWER
'list'
6) What are the 3 sequence types in Python? what do they represent/look like? -
ANSWER list: Ordered, mutable sequence; [1,23]
tuple: Ordered, immutable sequence; (1,2,3)
range: represents a range of values; e.g. range(5)
, 7) What are the characteristics of a set? - ANSWER Unordered, mutable collection of
unique elements. {1,2,3}
8) what is a dictionary mapping type? - ANSWER an unordered collection of key-
value pairs.
my_dict = {'key':'value', 'name':'John'}
9) What happens when an operation is performed that involves both an int and a float in
Python? - ANSWER the result is automatically promoted to a 'float'
10) What does the 'round(x, n) function do in Python? - ANSWER it rounds 'x' to 'n'
decimal places
11) What are the two main escape characters? - ANSWER \n : new line
\t : for a tab
12) What are the 3 components of a string slice? - ANSWER string [start:stop:step]
· Start: the index from which the slicing begins (inclusive)
· Stop: the index at which the slicing ends (exclusive)
· Step (optional): The step or stride between characters.
13) What does the string slicing operation 'text {::-1] do where text = "Hello, Python!"? -
ANSWER It reverses the string.
The 'step' portion of the slice is negative, indicating the stride between characters is
reversed.
14) What does the 'strip()' method do in Python? - ANSWER It removes leading and
trailing whitespaces from a string