wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python set 1

Total questions: 26

Worksheet time: 1hrs 18mins

Name
Class
Date
1.
What will be the output of the following Python code? >>> str1 = 'hello' >>> str2 = ', >>> str3 = 'world' >>> str1[-1:]
a)
olleh
b)
hello
c)
h
d)
o
2.
What will be the output of the following Python statement >>>"abcd"[2:]
a)
a
b)
ab
c)
cd
d)
dc
3.
What will be the output of the following Python code? '{a}{b}{a}'.format(a='hello', b='world')
a)
‘hello world’
b)
‘hello’ ‘world’ ‘hello'
c)
‘helloworldhello'
d)
‘hello’ ‘hello’ ‘world'
4.
What will be the output of the following Python code snippet ?X=”san-foundry print(“%56s”,X)
a)
56 blank spaces before san-foundry
b)
56 blank spaces before san and foundry
c)
56 blank spaces after san-foundry
d)
no change
5.
Which of the following operators has its associativity from right to left?
a)
+
b)
//
c)
%
d)
**
6.
What is the result of cmp(3, 1)?
a)
1
b)
0
c)
True
d)
false
7.
Select all options that print hello-how-are-you
a)
print(‘hello’, ‘how’, ‘are’, ‘you’)
b)
print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c)
print(‘hello-‘ + ‘how-are-you’)
d)
print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you')
8.
What data type is the object below?L = [1, 23, 'hello', 1]
a)
list
b)
dictionary
c)
array
d)
tuple
9.
What error occurs when you execute the following Python code snippet? apple = mango
a)
SyntaxError
b)
NameError
c)
ValueError
d)
TypeError
10.
Which type of programming does Python support?
a)
Object-oriented programming
b)
structure programming
c)
functional programming
d)
all of the mentioned
11.
What will be the value of the following Python expression?4 + 3 % 5
a)
7
b)
2
c)
4
d)
1
12.
Which of the following is used to define a block of code in Python language?
a)
Indentation
b)
Key
c)
Brackets
d)
All of the mentioned
13.
Python supports the creation of anonymous functions at runtime, using a construct called ____
a)
pi
b)
anonymous
c)
lambda
d)
none of the mentioned
14.
What is the order of precedence in python?
a)
Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b)
Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c)
Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d)
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
15.
Which of the following is the truncation division operator in Python?
a)
|
b)
//
c)
/
d)
%
16.
What will be the output of the following Python function?len(["hello",2, 4, 6])
a)
error
b)
6
c)
4
d)
3
17.
What will be the output of the following Python code snippet? for i in [1, 2, 3, 4][::-1]: print (i)
a)
4 3 2 1
b)
error
c)
1 2 3 4
d)
none of the mentioned
18.
What arithmetic operators cannot be used with strings in Python?
a)
*
b)
-
c)
+
d)
All of the mentioned
19.
To add a new element to a list we use which Python command?
a)
list1.addEnd(5)
b)
list1.addLast(5)
c)
list1.append(5)
d)
list1.add(5)
20.
Which of the following is a Python tuple?
a)
{1, 2, 3}
b)
{}
c)
[1, 2, 3]
d)
(1, 2, 3)
21.
What will be the output of the following Python expression?round(4.576)
a)
4
b)
4.6
c)
5
d)
4.5
22.
What will be the output of the following Python code print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
a)
)
b)
error
c)
Hello foo and bin
d)
None of the mentioned
23.
Which of the following is an invalid statement?
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
24.
Which is the correct operator for power(xy)?
a)
X^y
b)
X**y
c)
X^^y
d)
None of the mentioned
25.
What is the output of this expression, 3*1**3?
a)
27
b)
9
c)
3
d)
1
26.
Which of these in not a core data type?
a)
Lists
b)
Dictionary
c)
Tuples
d)
Class