- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
- Python Useful Resources
- Python - Questions and Answers
- Python - Quick Guide
- Python - Tools/Utilities
- Python - Useful Resources
- Python - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Online Quiz
Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Answer : C
Explanation
If the string is not found by method find() , it returns the integer -1.
Q 2 - Which of the following is false statement in python
Answer : D
Explanation
The built-in int() type constructor converts string and floating value to integer.
Q 3 - What is output of following code −
print('hijk'.partition('ab'))
Answer : C
Explanation
Since there are no separators in the given string so the output is the same string.
Q 4 - What is output of following code −
s = ''mnopqr '' i = ''m '' while i in s: print('i', end= '' '')
Answer : A
Q 5 - What is the output of the code?
def f(): global z print('z is: ', z) z=50 print('new value of global z is: ', z) f() print('Value of z is: ', z)
new value of global z is: 100
value of z is 100
new value of global z is: 100
value of z is 50
new value of global z is: 50
value of z is 100
new value of global z is: 50
value of z is 50
Answer : D
Explanation
Here in the above code ‘global’ keyword is used to state that ‘z’ is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of ‘z’ in the main block or outside the function.
Q 6 - What is the output of the following code?
class P: def __init__(self): self.__x=100 self.y=200 def print(self): print(self.__x, self.y) class C(P): def __init__(self): super().__init__() self.__x=300 self.y=400 d = C() d.print()
Answer : B
Explanation
In the above code x is a private variable declared in the class P. Thus value of x cannot be changed in the class C which inherits class P. But y is not a private variable thus its value can be changed.
Q 7 - Discuss the outcome of the code?
def func1(n): if(n==0): return 0 else: return(n+func1(n-1)) def func2(n, result): if(n==0): return(result) else: return(func2(n-1, n+result)) print(func1(4)) print(func2(4,0))
B - Func1 and Func2 are tail recursions.
Answer : B
Explanation
A function call is said to be tail recursive if there is nothing to do after the function returns except return its value.
Q 8 - Which method is used to convert raw byte data to a string?
Answer : B
Explanation
Decode is the method used to convert the raw byte data to a string.
Q 9 - Select the correct option to draw a rectangle centred at 50,50 with width and height as 50, 70 respectively.
A - Canvas.create_rect(50,50,50,70)
B - Canvas.create_rect(50,70,50,50)
Answer : C
Q 10 - Select the code for the following output?
A - Turtle.circle(20 , ''green '')