MCQ

Python MCQ and Answers – Variables And Operators – Part 1

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Variables And Operators”.
 

1. Python is case sensitive when handling variables?

A True

B False

C Depend on the system

D None of the above

A
Case is always important. Example:

>>>n=2
>>>N
Traceback (most recent call last):
       File "<shell#1>", line 1, in <module>
           N
       NameError: name 'N' is not defined
>>>
 

2. Which is the correct approach of declaring and initialising a variable, ‘a’ with value 10?

A int a; a=10

B int a=10

C a=10

D declare a=10

C
The correct way is a=10.
 

3. Which is not a valid variable name in Python?

A _str

B str

C str255

D 255str

D
Variable names should not start with a number.
 

4. Which of the following is not valid?

A _x = 5

B __x = 5

C __var__ = 5

D None of the above

D
All the declarations are valid.
 

5. Which of the following is not correct concerning variables in Python?

A Variable names in Python can’t start with a number. But, it can include numbers in any other position of the variable name.

B Variable names can start with an underscore.

C Data type of variable names must not be declared

D None of the mentioned

D
All the statements are correct.
 

6. What is the output of the following code : print (10//2) ?

A 5

B 5.5

C 5.0

D Error

A
Here print (10//2) we have used integer division to divid two integers.
 

7. Which of the following is the correct operator for xn?

A X^n

B X**n

C X^^n

D None of the above

B
In python, the power operator is x**n i.e. 2**3=8.
 

8. Which of the following is the floor division operator?

A /

B //

C %

D None of the above

B
When the operands are integer so python break off the fraction part and provids you the round off value, to get the exact answer use floor division. This is floor division. For ex, 7/2 = 3.5 but both of the operands are integer so answer of this expression in python is 3.
 

9. Is it possible to execute Mathematical operations on string?

A True

B False

B
You cannot execute mathematical operations on a string even if the string contains numbers, i.e ‘12345…’.
 

10. Which of the following are keyword in Python?

A not

B or

C with

D All of the above

D
All “not”, “or” and “with” are keywords. So, Option D is correct.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *