- 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 - How can we generate random numbers in python using methods?
Answer : D
Explanation
To generate random numbers we import random module and in that module we have these methods/functions.
uniform(x,y) returns a floating number in the range [x,y] random() returns a floating point number in the range [0, 1].
randint(x,y) returns a random integer number in the range [x, y].
Q 4 - What is output of following code −
def func(n): if(n==1): return 1; else: return(n+func(n-1)) print(func(4))
Answer : B
Q 5 - What is the output of the following code?
def nprint(message, n): while(n > 0): print(message) n-=1 nprint('z', 5)
Answer : D
Explanation
Because decrementing condition of ‘n’ is not present in the while loop.
Q 6 - What is the output of the following code?
eval(''1 + 3 * 2'')
Answer : D
Explanation
Eval is a method used to evaluate the values entered in the braces.
Q 7 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?
Answer : B & C.
Explanation
len(s) returns the length of the set and max(s) returns the maximum value in the set.
Q 8 - Which method is used to display a warning message in Python?
A - Tkinter.message.showmessage('message here')
B - Tkinter.message.sshowwarning('message here')
Answer : C
Explanation
For the type of message user want to display on the window of python there is a type of code according to it. Example for warning message user choose showwarning method.
Q 9 - Select the valid option for the following Output −
A - Canvas.Create_text(text= ''Hello! '')
B - Canvas.Create_text(30 , 40, text= ''Hello! '' ,filled= ''green '')
C - Canvas.Create_text(text= ''Hello! '' ,textcolor= ''Green'')
Answer : B
Explanation
Text is created in the canvas by using create_text method of canvas. Color of the text can be set according to the user which is specified under ‘filled’.
Q 10 - Best part is you can display images in various options in Python. Select the option where you can display an image −