Python test1-QB-CA1
Python test1-QB-CA1
Associativity – 1”.
Answer: a
Explanation: Although the presence of parenthesis does affect the order of precedence, in the case
shown above, it is not making a difference. The result of both of these expressions is 1.333333333.
Hence the statement is true.
4+3%5
a) 4
b) 7
c) 2
d) 0
View Answer
Answer: b
Explanation: The order of precedence is: %, +. Hence the expression above, on simplification results in 4
+ 3 = 7. Hence the result is 7.
A % B // A
a) 0.0
b) 0
c) 1.0
d) 1
View Answer
Answer: b
Explanation: The above expression is evaluated as: 16%15//16, which is equal to 1//16, which results in
0.
advertisement
4. Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **
View Answer
Answer: d
Explanation: All of the operators shown above have associativity from left to right, except
exponentiation operator (**) which has its associativity from right to left.
x = int(43.55+2/2)
a) 43
b) 44
c) 22
d) 23
View Answer
Answer: b
Explanation: The expression shown above is an example of explicit conversion. It is evaluated as
int(43.55+1) = int(44.55) = 44. Hence the result of this expression is 44.
2+4.00, 2**4.0
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)
View Answer
Answer: a
Explanation: The result of the expression shown above is (6.0, 16.0). This is because the result is
automatically rounded off to one decimal place.
2**(3**2)
(2**3)**2
2**3**2
a) 64, 512, 64
b) 64, 64, 64
c) 512, 512, 512
d) 512, 64, 512
View Answer
Answer: d
Explanation: Expression 1 is evaluated as: 2**9, which is equal to 512. Expression 2 is evaluated as 8**2,
which is equal to 64. The last expression is evaluated as 2**(3**2). This is because the associativity of **
operator is from right to left. Hence the result of the third expression is 512.
8/4/2, 8/(4/2)
a) (1.0, 4.0)
b) (1.0, 1.0)
c) (4.0. 1.0)
d) (4.0, 4.0)
View Answer
Answer: a
Explanation: The above expressions are evaluated as: 2/2, 8/2, which is equal to (1.0, 4.0).
float(22//3+3/3)
a) 8
b) 8.0
c) 8.3
d) 8.33
View Answer
Answer: b
Explanation: The expression shown above is evaluated as: float( 7+1) = float(8) = 8.0. Hence the result of
this expression is 8.0.
To practice all areas of Python, here is complete set of 1000+ Multiple Choice Questions and Answers.
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social
networks below and stay updated with latest contests, videos, internships and jobs!
a. 16
b. 32
c. 64
Hide Answer Workspace
Explanation: The maximum possible length of an identifier is not defined in the python language. It can
be of any number.
a. Zim Den
c. Niene Stom
Hide Answer Workspace
a. 1995
b. 1972
c. 1981
d. 1989
Hide Answer Workspace
Answer: (d) 1989
a. English
b. PHP
c. C
Hide Answer Workspace
Answer: (b) C
5) Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
Hide Answer Workspace
Answer: (a) .py
a. 2008
b. 2000
c. 2010
d. 2005
Hide Answer Workspace
Answer: (a) 2008
a. Key
b. Brackets
c. Indentation
d. None of these
Hide Answer Workspace
Answer: (c) Indentation
Explanation: Python uses indentation to define blocks of code. Indentations are simply spaces or tabs
used as an indicator that is part of the indent code child. As used in curly braces C, C++, and Java.
a. /
b. //
c. #
d. !
Hide Answer Workspace
Answer: (c) #
9) Which of the following statements is correct regarding the object-oriented programming concept in
Python?
Hide Answer Workspace
Answer: (b) Objects are real-world entities while classes are not real
Explanation: None
1. class Name:
2. def __init__(javatpoint):
3. javajavatpoint = java
4. name1=Name("ABC")
5. name2=name1
a. It will throw the error as multiple references to the same object is not possible
c. Both name1 and name2 will have reference to two different objects of class Name
Explanation: "name1" and "name2" refer to the same object, so id(name1) and id(name2) will have the
same value.
a. Object
b. Function
c. Attribute
d. Argument
Hide Answer Workspace
Answer: (b) Function
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
Hide Answer Workspace
Explanation: All declarations will execute successfully but at the expense of low readability.
13) Why does the name of local variables start with an underscore discouraged?
d. None of these
Hide Answer Workspace
Explanation: Since there is no concept of private variables in Python language, the major underscore is
used to denote variables that cannot be accessed from outside the class.
a. val
b. raise
c. try
d. with
Hide Answer Workspace
Answer: (a) val
15) Which of the following statements is correct for variable names in Python language?
b. Unlimited length
Hide Answer Workspace
Explanation: None
d. x_y_z_p = 5,000,000
Hide Answer Workspace
a. _val
b. val
c. try
d. _try_
Hide Answer Workspace
Answer: (c) try
Explanation: "try" is a keyword.
18) Which of the following operators is the correct option for power(ab)?
a. a ^ b
b. a**b
c. a ^ ^ b
d. a ^ * b
Hide Answer Workspace
Answer: (b) a**b
Hide Answer Workspace
20) Which one of the following has the same precedence level?
Hide Answer Workspace
Explanation: None
21) Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
Hide Answer Workspace
Answer: (d) Parentheses
a. val()
b. print()
c. print()
d. None of these
Hide Answer Workspace
Answer: (b) print()
Explanation: The print() function is a built-in function in python language that prints a value directly to
the system.
1. round(4.576)
a. 4
b. 5
c. 576
d. 5
Hide Answer Workspace
Answer: (d) 5
Explanation: The round function is a built-in function in the Python language that round-off the value
(like 3.85 is 4), so the output of this function will be 5.
a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z
Hide Answer Workspace
Answer: (c) (x**y) % z
Explanation: None
1. all([2,4,0,6])
a. False
b. True
c. 0
d. Invalid code
Hide Answer Workspace
Answer: (a) False
Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns a
true value. Hence, the output of this "all([2,4,0,6])" function will be false.
1. x = 1
2. while True:
3. if x % 5 = = 0:
4. break
5. print(x)
6. x + = 1
a. error
b. 2 1
c. 0 3 1
d. None of these
Hide Answer Workspace
Answer: (a) error