My Report (&Account)

Python Online Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)

Here is the complete list of test quizzes on Python.

1. What will be the output of the following Python code?

class Demo:
    def check(self):
        return " Demo's check "  
    def display(self):
        print(self.check())
class Demo_Derived(Demo):
    def check(self):
        return " Derived's check "
Demo().display()
Demo_Derived().display()

Question 1 of 50 (sanfoundry.com)

2. What does single-level inheritance mean?

Question 2 of 50 (sanfoundry.com)

3. The function used to alter the thickness of the pen to ‘x’ units:

Question 3 of 50 (sanfoundry.com)

4. What will be the output of the following Python code snippet?

print('\t'.isspace())

Question 4 of 50 (sanfoundry.com)

5. What will be the output of the following Python code?

a={"a":1,"b":2,"c":3}
b=dict(zip(a.values(),a.keys()))
print(b)

Question 5 of 50 (sanfoundry.com)

6. _______________________ exceptions are raised as a result of an error in opening a particular file.

Question 6 of 50 (sanfoundry.com)

7. What will be the output of the following Python code?

def f(x):
    def f1(*args, **kwargs):
        print("*"* 5)
        x(*args, **kwargs)
        print("*"* 5)
    return f1
def a(x):
    def f1(*args, **kwargs):
        print("%"* 5)
        x(*args, **kwargs)
        print("%"* 5)
    return f1
@f
@a
def p(m):
    print(m)
p("hello")

Question 7 of 50 (sanfoundry.com)

8. What will be the output of the following Python code?

list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)

Question 8 of 50 (sanfoundry.com)

9. What will be the output of the following Python code?

e="butter"
def f(a): print(a)+e
f("bitter")

Question 9 of 50 (sanfoundry.com)

10. What will be the output of the following Python code?

print('{a}{b}{a}'.format(a='hello', b='world'))

Question 10 of 50 (sanfoundry.com)

11. In Python, which core data type is used to store values in the form of key–value pairs?

Question 11 of 50 (sanfoundry.com)

12. What will be the output of the following Python code?

print(list("a#b#c#d".split('#')))

Question 12 of 50 (sanfoundry.com)

13. What will be the output of the following Python code?

def display(b, n):
    while n > 0:
        print(b,end="")
        n=n-1
display('z',3)

Question 13 of 50 (sanfoundry.com)

14. What will be the output of the following Python code snippet?

print('cd'.partition('cd'))

Question 14 of 50 (sanfoundry.com)

15. The expression 2**2**3 is evaluates as: (2**2)**3.

Question 15 of 50 (sanfoundry.com)

16. Which function is used to close a file in python?

Question 16 of 50 (sanfoundry.com)

17. Which type of copy is shown in the following python code?

l1=[[10, 20], [30, 40], [50, 60]]
ls=list(l1)
ls
[[10, 20], [30, 40], [50, 60]]

Question 17 of 50 (sanfoundry.com)

18. What will be the output of the following Python code snippet?

print('ab\ncd\nef'.splitlines())

Question 18 of 50 (sanfoundry.com)

19. To retrieve the character at index 3 from string s="Hello" what command do we execute (multiple answers allowed)?

Question 19 of 50 (sanfoundry.com)

20. What will be the output of the following Python code?

a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)

Question 20 of 50 (sanfoundry.com)

21. What will be the output of the following Python code if a=10 and b =20?

a=10
b=20
a=a^b
b=a^b
a=a^b
print(a,b)

Question 21 of 50 (sanfoundry.com)

22. What will be the output of the following Python code?

a=(1,2,(4,5))
b=(1,2,(3,4))
print(a<b)

Question 22 of 50 (sanfoundry.com)

23. What will be the output of the following Python code?

s={1, 2, 3}
s.update(4)
print(s)

Question 23 of 50 (sanfoundry.com)

24. What will be the output of the following Python code?

x = [12.1, 34.0]
print(len(' '.join(list(map(str, x)))))

Question 24 of 50 (sanfoundry.com)

25. What is the default value of encoding in encode()?

Question 25 of 50 (sanfoundry.com)

26. What will be the output of the following Python code?

def c(f):
    def inner(*args, **kargs):
        inner.co += 1
        return f(*args, **kargs)
    inner.co = 0
    return inner
@c
def fnc():
    pass
if __name__ == '__main__':
    fnc()
    fnc()
    fnc()
    print(fnc.co)

Question 26 of 50 (sanfoundry.com)

27. What will be the output of the following Python code?

l1=[1,2,3]
l2=[4,5,6]
print([x*y for x in l1 for y in l2])

Question 27 of 50 (sanfoundry.com)

28. Which function is used to write all the characters?

Question 28 of 50 (sanfoundry.com)

29. What will be the output of the following Python code?

a=(1,2)
b=(3,4)
c=a+b
print(c)

Question 29 of 50 (sanfoundry.com)

30. What will be the output of the following Python function, assuming that the random library has already been included?

import random
print(random.shuffle[1,2,24])

Question 30 of 50 (sanfoundry.com)

31. State whether true or false.

import time
s = time.time()
t = time.time()
print(s == t)

Question 31 of 50 (sanfoundry.com)

32. What will be the output of the following Python code?

def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(9)

Question 32 of 50 (sanfoundry.com)

33. Observe the following Python code?

def a(n):
    if n == 0:
        return 0
    else:
        return n*a(n - 1)
def b(n, tot):
    if n == 0:
        return tot
    else:
        return b(n-2, tot-2)

Question 33 of 50 (sanfoundry.com)

34. Which of the following is not the correct syntax for creating a set?

Question 34 of 50 (sanfoundry.com)

35. How are required arguments specified in the function heading?

Question 35 of 50 (sanfoundry.com)

36. What will be the output of the following Python code?

import turtle
t=turtle.Pen()
t.backward(100)
t.penup()
t.right(45)
t.isdown()

Question 36 of 50 (sanfoundry.com)

37. What will be the output of the following Python code snippet?

print('%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'})

Question 37 of 50 (sanfoundry.com)

38. Which of the following functions creates a Python object?

Question 38 of 50 (sanfoundry.com)

39. Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])

Question 39 of 50 (sanfoundry.com)

40. What will be the output of the following Python code?

x = "abcdef"
i = "a"
while i in x:
    x = x[:-1]
    print(i, end = " ")

Question 40 of 50 (sanfoundry.com)

41. Which of the following will result in an error?

Question 41 of 50 (sanfoundry.com)

42. What is returned by math.isfinite(float('nan'))?

Question 42 of 50 (sanfoundry.com)

43. What will be the output of the following Python code?

fo = open("foo.txt", "wb")
print("Name of the file: ", fo.name)
fo.flush()
fo.close()

Question 43 of 50 (sanfoundry.com)

44. What will be the output of the following Python code?

if (9 < 0) and (0 < -9):
    print("hello")
elif (9 > 0) or False:
    print("good")
else:
    print("bad")

Question 44 of 50 (sanfoundry.com)

45. What will be the output of the following Python code?

import random
print(random.randrange(1,100,10))

Question 45 of 50 (sanfoundry.com)

46. What will be the output of the following Python function?

print(sum([1,2,3]))
print(sum(2,4,6))

Question 46 of 50 (sanfoundry.com)

47. Which of the following isn’t true about dictionary keys?

Question 47 of 50 (sanfoundry.com)

48. What does built-in function help do in context of classes?

Question 48 of 50 (sanfoundry.com)

49. What will be the output of the following Python code?

example = "snow world"
print(example[3] = 's')

Question 49 of 50 (sanfoundry.com)

50. Which of the following isn’t true about main modules?

Question 50 of 50 (sanfoundry.com)


 

Topic wise Test Quizzes on Python

Python tests, quizzes, and exams are great ways to learn and test your Python programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on Python basics, operators, loops, strings, lists, tuples, sets, dictionaries, functions, modules, files, and exceptions. Start the Python online test now!



Python Programming Certification Test

Python Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Python Programming Internship Test

If you scored either Grade A* or Grade A in our Python Programming Internship Test, then you can apply for Internship at Sanfoundry in Python Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Python Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on Python Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
Manish Bhojasia – Founder & CTO at Sanfoundry

I’m Manish, Founder & CTO at Sanfoundry, with 25+ years of experience across Linux systems, SAN technologies, advanced C programming, and building large-scale, performance-driven learning and certification platforms focused on clear skill validation.

LinkedIn  ·  YouTube MasterClass  ·  Telegram Classes  ·  Career Guidance & Conversations