What is the expected output of the following code?
What is the expected output of the following code? z = y = x = 1 print(x, y, z, sep='*')A . x*y*z B. 111* C. x y z D. 1*1*1 E. 1 1 1 F. The code is erroneous.View AnswerAnswer: D Explanation: Topic: multiple assignment print() with sep parameter Try...
A function definition starts with the keyword:
A function definition starts with the keyword:A . def B. function C. funView AnswerAnswer: A Explanation: Topic: def Try it yourself: def my_first_function(): print('Hello') my_first_function() # Hello https://www.w3schools.com/python/python_functions.asp
Which of the following variable names are illegal? (Select two answers)
Which of the following variable names are illegal? (Select two answers)A . TRUE B. True C. true D. andView AnswerAnswer: B, D Explanation: Topics: variable names keywords True and Try it yourself: TRUE = 23 true = 42 # True = 7 # SyntaxError: cannot assign to True # and...
What is the expected output of the following code?
What is the expected output of the following code? num = 1 def func(): num = num + 3 print(num) func() print(num)A . 4 1 B. 4 4 C. The code is erroneous. D. 1 4 E. 1 1View AnswerAnswer: C Explanation: Topics: def shadowing Try it yourself: num =...
Strings in Python are delimited with:
Strings in Python are delimited with:A . backslashes (i.e., ) B. double quotes (i.e., ") or single quotes (i.e., ') C. asterisks (i.e., *) D. dollar symbol (i.e., $)View AnswerAnswer: B Explanation: Topics: strings quotes Try it yourself: print("Hello") # Hello print('World') # World Unlike in other programming languages, in...
Which of the variables will contain False?
Consider the following code snippet: w = bool(23) x = bool('') y = bool(' ') z = bool([False]) Which of the variables will contain False?A . z B. x C. y D. wView AnswerAnswer: B Explanation: Topic: type casting with bool() Try it yourself: print(bool(23)) # True print(bool('')) # False...
What is the expected output of the following code?
What is the expected output of the following code? list1 = [1, 3] list2 = list1 list1[0] = 4 print(list2)A . [1, 4] B. [4, 3] C. [1, 3, 4] D. [1, 3]View AnswerAnswer: B Explanation: Topics: list reference of a mutable data type Try it yourself: list1 = [1,...
What is the expected output of the following code?
What is the expected output of the following code? x = True y = False z = False if not x or y: print(1) elif not x or not y and z: print(2) elif not x or y or not y and x: print(3) else: print(4)A . 4 B. 3...
What is the expected output of the following code?
What is the expected output of the following code? def func(x): return 1 if x % 2 != 0 else 2 print(func(func(1)))A . The code is erroneous. B. None C. 2 D. 1View AnswerAnswer: D Explanation: Topics: def conditional expression (if else) modulus operator not equal to operator Try it...
What will be the output of the following code snippet?
What will be the output of the following code snippet? d = {} d[1] = 1 d['1'] = 2 d[1] += 1 sum = 0 for k in d: sum += d[k] print(sum)A . 3 B. 4 C. 1 D. 2View AnswerAnswer: B Explanation: Topics: for dictionary indexes add and...