0% found this document useful (0 votes)
3K views

Python Objective Questions For Beginners - CppBuzz

The document contains 47 multiple choice questions about Python programming. It covers topics like Python keywords, operators, data types, functions, classes and objects. For each question, there are 4 answer options and the correct answer is highlighted. The questions range from beginner to expert level and cover basic syntax, variables, conditionals, loops, functions, OOP concepts etc. Each question also lists the difficulty level and category.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

Python Objective Questions For Beginners - CppBuzz

The document contains 47 multiple choice questions about Python programming. It covers topics like Python keywords, operators, data types, functions, classes and objects. For each question, there are 4 answer options and the correct answer is highlighted. The questions range from beginner to expert level and cover basic syntax, variables, conditionals, loops, functions, OOP concepts etc. Each question also lists the difficulty level and category.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CppBuzz.

com Search topic

Home C C++ Java Python Perl PHP SQL JavaScript Linux Online Test

Home » Python » Python Objective Questions

Python Objective Questions - 53

Question: 1

Select the reserved


keyword in python

(A) else
(B) import
(C) raise
(D) All of these

Show Ans

Ans: D

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 2

Which of the
following symbols are

(A) //
(B) ''
(C) /**/
(D) #

Show Ans

Ans: D

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 3

Are nested if-else


are allowed in

(A) Yes
(B) No
Show Ans

Ans: A

Forum
Level: Beginner Category: conditional
[Posted by: Admin | Chicago, USA]

Question: 4

Which keyword is used


to define methods in

(A) function
(B) def
(C) method
(D) All of these

Show Ans

Ans: B

Forum
Level: Beginner Category: methods
[Posted by: Admin | Chicago, USA]

Question: 5

Which of the
following is correct

(A) fruit = 'banana'


(B) fruit = "banana"
(C) fruit = banana
(D) fruit = (banana)

Show Ans

Ans: A

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 6

Which predefined
Python function is

(A) length()
(B) len()
(C) strlen()
(D) stringlength()

Show Ans
Ans: B

Forum
Level: Beginner Category: methods
[Posted by: Admin | Chicago, USA]

Question: 7

Python allows string


slicing. What is the
output of below code:

s='cppbuzz chicago'

(A) pbuzz
(B) buzzc
(C) bu
(D) None of these

Show Ans

Ans: C

Forum
Level: Beginner Category: methods
[Posted by: Admin | Chicago, USA]

Question: 8

Syntax of constructor
in Python?

(A) def __init__()


(B) def _init_()
(C) _init_()
(D) All of these

Show Ans

Ans: A

Forum
Level: Beginner Category: classesAndobjects
[Posted by: Admin | Chicago, USA]

Question: 9

How to find the last


element of list in

(A) bikes[0]
(B) bikes[-1]
(C) bikes[lpos]
(D) bikes[:-1]

Show Ans
Ans: B

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 10

What is correct
syntax to copy one

(A) listA = listB[]


(B) listA = listB[:]
(C) listA = listB[]()
(D) listA = listB

Show Ans

Ans: B

Forum
Level: Practionar Category: other
[Posted by: Admin | Chicago, USA]

Question: 11

If a='cpp', b='buzz'
then which of the

(A) a+b
(B) a+''+b
(C) a+""+b
(D) All of the above

Show Ans

Ans: D

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 12

If a='cpp', b='buzz'
then what is the
output of:
c = a-b

(A) cpp-buzz
(B) cppbuzz
(C) TypeError: unsupported operand
(D) None of the above

Show Ans
Ans: C

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 13

a = 8.6
b = 2
print a//b

(A) 4.3
(B) 4.0
(C) 4
(D) compilation error

Show Ans

Ans: B

Forum
Level: Beginner Category: operators
[Posted by: Harshit Gupta | Allahabad,India]

Question: 14

a = True
b = False
c = True

if not a or b:
print "a"
elif not a or not b
and c:
print "b"
elif not a or b or
not b and a:
print "c"
else:
print "d"

(A) a
(B) b
(C) c
(D) d

Show Ans

Ans: B

Forum
Level: Beginner Category: variables
[Posted by: Harshit Gupta | Allahabad,India]

Question: 15
class test:
def
__init__(self):
print "Hello
World"
def
__init__(self):
print "Bye

(A) Hello World


(B) Compilation Error
(C) Bye World
(D) Ambiguity

Show Ans

Ans: C

Forum
Level: Beginner Category: variables
[Posted by: Harshit Gupta | Allahabad,India]

Question: 16

The format function,


when applied on a

(A) list
(B) bool
(C) int
(D) str

Show Ans

Ans: D

Forum
Level: Beginner Category: variables
[Posted by: Harshit Gupta | Allahabad,India]

Question: 17

The format function,


when applied on a

(A) list
(B) bool
(C) int
(D) str

Show Ans

Ans: D

Forum
Level: Beginner Category: methods
[Posted by: Harshit Gupta | Allahabad,India]
Question: 18

print(chr(ord('b')+1)
)

(A) b
(B) syntax error
(C) c
(D) b+1

Show Ans

Ans: C

Forum
Level: Beginner Category: other
[Posted by: Harshit Gupta | Allahabad,India]

Question: 19

Which statement is
correct....??

(A) List is mutable && Tuple is immutable


(B) List is immutable && Tuple is mutable
(C) Both are Immutable
(D) Both are Mutable.

Show Ans

Ans: A

Forum
Level: Beginner Category: variables
[Posted by: Shani pratap singh | Pune]

Question: 20

What is PEP8?

PEP8 is a set of
coding guidelines in

Show Ans

Ans: A

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 21
State the difference
between tuples and
lists in Python.

Show Ans

Ans: A

Forum
Level: Practionar Category: other
[Posted by: Admin | Chicago, USA]

Question: 22

Write a sorting
algorithm for a
numerical dataset in
Python

Ans: The following


code can be used to
sort a list in
Python:

Show Ans

Ans: A

Forum
Level: Practionar Category: arrays
[Posted by: Admin | Chicago, USA]

Question: 23

What is pickling and


unpickling?

Ans: Pickle module

Show Ans

Ans: A

Forum
Level: Practionar Category: other
[Posted by: Admin | Chicago, USA]

Question: 24

What is the maximum


possible length of an

(A) 32 characters
(B) 63 characters
(C) 79 characters
(D) None of the above
Show Ans

Ans: D

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 25

Which of the
following is an

(A) abc = 1,000,000


(B) a b c = 1000 2000 3000
(C) a,b,c = 1000, 2000, 3000
(D) a_b_c = 1,000,000

Show Ans

Ans: B

Forum
Level: Expert Category: variables
[Posted by: Admin | Chicago, USA]

Question: 26

Suppose list1 is [2,


33, 222, 14, 25],

(A) Error
(B) 25
(C) None
(D) 2

Show Ans

Ans: B

Forum
Level: Practionar Category: arrays
[Posted by: Admin | Chicago, USA]

Question: 27

To open a file
c:cppbuzz.txt for

(A) outfile = open(file = “c:cppbuzz.txt”, “o”)


(B) outfile = open(“c:cppbuzz.txt”, “r”)
(C) outfile = open(“c:cppbuzz.txt”, “w”)
(D) outfile = open(“c:cppbuzz.txt”, “r”)

Show Ans
Ans: C

Forum
Level: Practionar Category: filehandling
[Posted by: Admin | Chicago, USA]

Question: 28

What is dictionary in
Python?

Ans:
The built-in

Show Ans

Ans: A

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 29

Which of the
following date format
should be used in
place of ???

import time

(A) “%d/%m/%Y”
(B) “%d/%M/%y”
(C) “%D/%M/%Y”
(D) “%d/%m/%y”

Show Ans

Ans: A

Forum
Level: Practionar Category: regularexpressions
[Posted by: Admin | Chicago, USA]

Question: 30

Which one of the


following is not a

(A) Class
(B) List
(C) Dictionary
(D) Tuple

Show Ans

Ans: A
Forum
Level: Beginner Category: classesAndobjects
[Posted by: Admin | Chicago, USA]

Question: 31

What will be the


output of 7^10 in

(A) 13
(B) 2
(C) 15
(D) None of these

Show Ans

Ans: A

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 32

How following
evaluates in Python?
round(0.5) –

(A) 0
(B) 1
(C) 2
(D) 0.5

Show Ans

Ans: C

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 33

Find out output of


following code
snippet

>>>str="cppbuzz"

(A) uzz
(B) cpp
(C) buzz
(D) cppb

Show Ans
Ans: B

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 34

Is it possible to use
round function

(A) Yes
(B) No

Show Ans

Ans: A

Forum
Level: Practionar Category: methods
[Posted by: Admin | Chicago, USA]

Question: 35

What is the data type


of X in X = [12.12,

(A) Tuple
(B) Array
(C) Dictionary
(D) List

Show Ans

Ans: D

Forum
Level: Practionar Category: variables
[Posted by: Admin | Chicago, USA]

Question: 36

Which of the
following data type

(A) Class
(B) List
(C) Tuple
(D) Dictionary

Show Ans

Ans: D

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 37

Select the correct


code to print
cppbuzz-chicago

(A) print('cppbuzz-' + 'chicago');


(B) print('cppbuzz' + '-chicago');
(C) print('cppbuzz' + '-' + 'chicago');
(D) All of the above

Show Ans

Ans: D

Forum
Level: Beginner Category: operators
[Posted by: Admin | Chicago, USA]

Question: 38

Which of the
following operators

(A) //
(B) %
(C) /
(D) None of the above

Show Ans

Ans: A

Forum
Level: Beginner Category: operators
[Posted by: Admin | Chicago, USA]

Question: 39

19 % 2 in python

(A) 17
(B) 2
(C) 0
(D) None of these

Show Ans

Ans: D

Forum
Level: Beginner Category: operators
[Posted by: Admin | Chicago, USA]
Question: 40

What is the
associativity of

(A) Depends on operators


(B) Left to Right
(C) Right to Left
(D) Depends on Python Compiler

Show Ans

Ans: B

Forum
Level: Beginner Category: operators
[Posted by: Admin | Chicago, USA]

Question: 41

Which of the
following has more

(A) +
(B) /
(C) -
(D) ()

Show Ans

Ans: D

Forum
Level: Beginner Category: operators
[Posted by: Admin | Chicago, USA]

Question: 42

Is Python case
sensitive?

(A) Yes
(B) No
(C) Depends on Python Version

Show Ans

Ans: A

Forum
Level: Beginner Category: other
[Posted by: Admin | Chicago, USA]

Question: 43
Which of the
following variable is

(A) __str
(B) __str
(C) _str_
(D) None of these

Show Ans

Ans: D

Forum
Level: Beginner Category: variables
[Posted by: Admin | Chicago, USA]

Question: 44

Select the command to


Find and print Data
types using the Type
command.
name="Hello World"

(A) type(name)
(B) print(type(name))
(C) print(name)
(D) type()

Show Ans

Ans: B

Forum
Level: Beginner Category: variables
[Posted by: Mayank Patel | Des Moines, IA]

Question: 45

what is the output


for:
name="Hello World"
print(type(name))

(A) Hello World


(B) hello World
(C) <class 'str'>
(D) str

Show Ans

Ans: C

Forum
Level: Practionar Category: variables
[Posted by: Mayank Patel | Des Moines, IA]
Question: 46

Is Tuple mutable?

(A) Yes
(B) No

Show Ans

Ans: B

Forum
Level: Beginner Category: other
[Posted by: Mayank Patel | Des Moines, IA]

Question: 47

2) What is the output


of the following
program?

from math import *


a = 2.13
b = 3.7777
c = -3.12
print(int(a),

(A) a) 2 3 -4 3
(B) b) 2 3 -3 3.12
(C) c) 2 4 -3 3
(D) d) 2 3 -4 3.12

Show Ans

Ans: B

Forum
Level: Expert Category: other
[Posted by: sandeep kumar yadav | ambala,haryana]

Question: 48

import re
sum = 0

pattern = 'back'
if re.match(pattern,
'backup.txt'):
sum += 1
if re.match(pattern,
'text.back'):
sum += 2
if re.search(pattern,
'backup.txt'):
sum += 4
if re.search(pattern,
'text.back'):
(A) 3
(B) 13
(C) 7
(D) 15

Show Ans

Ans: B

Forum
Level: Beginner Category: regularexpressions
[Posted by: Abhinay Ankur | MMU MULLANA AMBALA INDIA]

Question: 49

Which of the
following print
statements will print

(A) print(names.append(" "))


(B) print(" ".join(names))
(C) print(names.join("%s ", names))
(D) print(names.concatenate(" "))

Show Ans

Ans: B

Forum
Level: Beginner Category: other
[Posted by: Abhinay Ankur | MMU MULLANA AMBALA INDIA]

Question: 50

Which of these is not


a core data type?

(A) (A) Lists


(B) (B) Dictionary
(C) (C) Tuples
(D) (D) Class

Show Ans

Ans: D

Forum
Level: Expert Category: other
[Posted by: sandeep kumar yadav | MMU MULLANA,AMBALA,HARYANA]

Question: 51

What data type is the


object below ?
L = [1, 23, ‘hello’,
(A) Tuple
(B) Dictionary
(C) List
(D) Array

Show Ans

Ans: C

Forum
Level: Expert Category: other
[Posted by: sandeep kumar yadav | MMU MULLANA,AMBALA,HARYANA]

Question: 52

What is an exception

(A) Error
(B) Compile time error
(C) Run time error
(D) None

Show Ans

Ans: C

Forum
Level: Beginner Category: exceptions
[Posted by: Gayatri | Piduguralla]

Question: 53

How many types of


funtional arguments

(A) 4
(B) 3
(C) 5
(D) None

Show Ans

Ans: A

Hint:
The funtional arguments are

Forum
Level: Beginner Category: other
[Posted by: Gayatri | Andrapradesh]

[Contribute Here]

You might also like