TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Python Functions Quiz Part-2
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Python QuizzesPython Tutorials

Python Functions Quiz Part-2

Last updated: Nov 05, 2023 12:10 am
By Meenakshi Agarwal
Share
13 Min Read
Python Functions Quiz Part-2 for Experienced Programmers
Python Functions Quiz Part-2
SHARE

Hey, there experienced Python programmers, are you ready to test your skills with our Python Functions Quiz Part-2?

Contents
Q-1.  What is the output of the following code snippet?Q-2. What is the output of the following code snippet?Q-3.Which of the following function calls can be used to invoke the below function definition?Q-4. What is the output of the following code snippet?Q-5.  What is the value of num after the function call?Q-6. What is the output of the following code snippet?Q-7. What is the output of the following code snippet?Q-8. What is the output of the following code snippet?Q-9. What is the output of the following code snippet?Q-10. What is the output of the following code snippet?Q-11. What is the output of the following code snippet?Q-12. What is the output of the following code snippet?Q-13. What is the order of usage of  *args, **kwargs, and formal args in the function header?Q-14. What is the output of the following code snippet?Q-15. What is the output of the following code snippet?Q-16. What is the output of the following code snippet?Q-17. What is the output of the following code snippet?Q-18. What is the output of the following code snippet?Q-19. What is the output of the following code snippet?Q-20. What is the output of the following code snippet?Q-21. What is the output of the following code snippet?Suggested Readings

This quiz features 21 medium to high-complexity questions that will put your knowledge to the test. But before you dive in, let’s talk about the importance of functions in Python.

Functions are a powerful tool that helps organize your code into logical blocks, making it easier to read, modularize, and reusable. They are also a great way to create interfaces for other programmers.

Did you know that in Python, functions can return multiple values? It’s true! Return the results as a tuple.

And if you ever need to list down the functions of a module, you can use the <getmembers()> method of the <inspect> module.

So, if you’re up for a challenge, take our Python Functions Quiz Part-2 now. Good luck and have fun!

Take on our Advance Level Python Functions Quiz Part-2!

Python Functions Quiz Part-2 for Experienced Programmers
Python Functions Quiz Part-2

Q-1.  What is the output of the following code snippet?

def func( mylist ):
   "This changes a passed list into this function"
   mylist = [1,2,3,4]; # This would assign new reference in mylist
   print ("Values inside the function: ", mylist)
   return

mylist = [10,20,30];
func( mylist );
print ("Values outside the function: ", mylist)
  • A. Values inside the function:  [1, 2, 3, 4]
    Values outside the function:  [10, 20, 30]
  • B. Values inside the function:  [10, 20, 30]
    Values outside the function:  [10, 20, 30]
  • C. Values inside the function:  [1, 2, 3, 4]
    Values outside the function: [1, 2, 3, 4]
  • D. None of the above
Hover here to view the answer!
Answer. A

 

Q-2. What is the output of the following code snippet?

x = 50
 
def func():
    global x
 
    print('x is', x)
    x = 2
    print('Changed global x to', x)
func()
print('The value of x is', x)
  • A. x is 50
    Changed global x to 2
    The value of x is 50
  • B. x is 50
    Changed global x to 2
    The value of x is 2
  • C. x is 50
    Changed global x to 50
    The value of x is 50
  • D. None of the mentioned
Hover here to view the answer!
Answer. B

 

Q-3.Which of the following function calls can be used to invoke the below function definition?

def test(a, b, c, d)
  • A. test(1, 2, 3, 4)
  • B. test(a = 1, 2, 3, 4)
  • C. test(a = 1, b = 2, c = 3, 4)
  • D. test(a = 1, b = 2, c = 3, d = 4)
  • E. test(1, 2, 3, d = 4)
Hover here to view the answer!

Answer. A, D, and E

Note: B and C lead to SyntaxError: positional argument follows keyword argument

 

Q-4. What is the output of the following code snippet?

def test(a, b=5, c=10):
    print('a is', a, 'and b is', b, 'and c is', c)
 
test(3, 7)
test(25, c = 24)
test(c = 50, a = 100)
  • A. a is 7 and b is 3 and c is 10
    a is 25 and b is 5 and c is 24
    a is 5 and b is 100 and c is 50
  • B. a is 3 and b is 7 and c is 10
    a is 5 and b is 25 and c is 24
    a is 50 and b is 100 and c is 5
  • C. a is 3 and b is 7 and c is 10
    a is 25 and b is 5 and c is 24
    a is 100 and b is 5 and c is 50
  • D. None of the above
Hover here to view the answer!
Answer. C

 

Q-5.  What is the value of num after the function call?

def myfunc(text, num):
    while num > 0:
        num = num - 1

num=4
myfunc('Hello', num)
  • A. 4
  • B. 3
  • C. 0
  • D. 1
Hover here to view the answer!
Answer. A

 

Q-6. What is the output of the following code snippet?

def func(x = 1, y = 2):
    return x + y, x - y

x, y = func(y = 2, x = 1)
print(x, y)
  • A. 1 3
  • B. 3 1
  • C. The program has a runtime error because the function returns the multiple values
  • D. 3 -1
  • E. -1 3
Hover here to view the answer!
Answer. D

 

Q-7. What is the output of the following code snippet?

def func():
    text = 'Welcome'
    name = (lambda x:text + ' ' + x)
    return name
 
msg = func()
print(msg('All'))
  • A. Welcome All
  • B. All Welcome
  • C. All
  • D. Welcome
Hover here to view the answer!
Answer. A

 

Q-8. What is the output of the following code snippet?

min = (lambda x, y: x if x < y else y)
print(min(101*99, 102*98))
  • A. 9997
  • B. 9999
  • C. 9996
  • D. 9998
Hover here to view the answer!
Answer. C

 

Q-9. What is the output of the following code snippet?

def func(x, y=2):
    num = 1
    for i in range(y):
       num = num * x
    return num
print (func(4))
print (func(4, 4))
  • A. 8 16
  • B. 16 256
  • C. 32 1024
  • D. 128 1256
Hover here to view the answer!
Answer. B

 

Q-10. What is the output of the following code snippet?

def add(*args):
   '''The function returns the addition 
   of all values'''
   r = 0
   for i in args:
      r += i
   return r
print (add.__doc__)
print (add(1, 2, 3))
print (add(1, 2, 3, 4, 5))
  • A. The function returns the addition
    of all values
    6 15
  • B. 6 15
  • C. 123 12345
  • D. 6 120
Hover here to view the answer!
Answer. A

 

Q-11. What is the output of the following code snippet?

def addFunc(item):
    item += [1]

mylist = [1, 2, 3, 4]
addFunc(mylist)
print (len(mylist))
  • A.  2
  • B.  4
  • C.  5
  • D.  An exception is thrown
Hover here to view the answer!
Answer. C

 

Q-12. What is the output of the following code snippet?

def heading(str):
    print ("+++%s+++" % str)
heading.id = 1
heading.text = "Python functions"
heading("%d %s" % (heading.id, heading.text))
  • A.  +++%s+++
  • B.  Python functions
  • C.  +++Python functions+++
  • D.  +++1 Python functions+++
Hover here to view the answer!
Answer. D

 

Q-13. What is the order of usage of  *args, **kwargs, and formal args in the function header?

  • A.  some_func(formal_args, *args, **kwargs)
  • B.  some_func(**kwargs, *args, formal_args)
  • C.  some_func(*args, **kwargs, formal_args)
  • D.  some_func(*args, formal_args, **kwargs)
Hover here to view the answer!
Answer. A

 

Q-14. What is the output of the following code snippet?

def test_var_args(param1, *args):
   print (type(args))

test_var_args('delhi', 'noida', 'gurgaon', 'ghaziabad')
  • A.  str
  • B.  int
  • C.  tuple
  • D.  list
  • E.  dict
Hover here to view the answer!
Answer. C

 

Q-15. What is the output of the following code snippet?

def test_var_args(param1, **kwargs):
   print (type(kwargs))

test_var_args('capitals', India='New Delhi',
Australia='Canberra', China='Beijing')
  • A.  str
  • B.  int
  • C.  tuple
  • D.  list
  • E.  dict
Hover here to view the answer!
Answer. E

 

Q-16. What is the output of the following code snippet?

def test_var_args(farg, *args):
    print ("formal arg:", farg)
    for arg in args:
        print ("another arg:", arg)
test_var_args(1, "two", 3)
  • A.  formal arg: 1
    another arg: two
    another arg: 3
  • B.  formal arg: 1
    another arg: two
  • C.  An exception is thrown
  • D.  None of the above
Hover here to view the answer!
Answer. A

 

Q-17. What is the output of the following code snippet?

def test_var_kwargs(farg, **kwargs):
    print ("formal arg:", farg)
    for key in kwargs:
        print ("another keyword arg: %s: %s" % (key, kwargs[key]))
test_var_kwargs(farg=1, myarg2="two", myarg3=3)
  • A.  formal arg: 1
    another keyword arg: myarg2: two
    another keyword arg: myarg3: 3
  • B.  formal arg: 1
    another keyword arg: myarg2: two
  • C.  An exception is thrown
  • D.  None of the above
Hover here to view the answer!
Answer. A

 

Q-18. What is the output of the following code snippet?

myList = [1, 2, 3, 4, 5]
def func(x):
    x.pop()
    x.pop()
    x.insert(-1, 0)
    print ("Inside func():", x)
    
func(myList)    
print ("After the function call:", myList)
  • A.  Inside func(): [1, 2, 3, 0]
    After the function call: [1, 2, 3, 4, 5]
  • B.  Inside func(): [0, 1, 2, 3]
    After the function call: [0, 1, 2, 3]
  • C.  Inside func(): [1, 2, 3, 0]
    After the function call: [1, 2, 3, 0]
  • D.  Inside func(): [1, 2, 0, 3]
    After function call: [1, 2, 0, 3]
Hover here to view the answer!
Answer. D

 

Q-19. What is the output of the following code snippet?

nums = range(2, 50) 
for i in range(2, 8): 
    nums = list(filter(lambda x: x == i or x % i, nums))
print (nums)
  • A. [2, 3, 4, 5, 6, 7, 8]
  • B. [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
  • C. [2, 3, 5, 6, 7, 10, 15, 19, 20, 27, 35, 41, 49]
  • D. [2, 3, 5, 9, 13, 17, 26, 31, 35, 37, 41, 43, 47, 49]
Hover here to view the answer!
Answer. B

 

Q-20. What is the output of the following code snippet?

text = 'Welcome to the world of Python'
words = text.split()
length = list(map(lambda word: len(word), words))
print (length)
  • A. [7, 2, 3, 5, 2, 6]
  • B. [30]
  • C. [7, 3, 4, 5, 6, 3]
  • D. [30, 23, 20, 15, 13, 7]
Hover here to view the answer!
Answer. A

 

Q-21. What is the output of the following code snippet?

from functools import reduce
f = lambda a,b: a if (a > b) else b
num = reduce(f, [47,11,42,102,13])
print (num)
  • A. 47
  • B. 42
  • C. 102
  • D. 11
Hover here to view the answer!
Answer. C

 

Level Up Your Python Function Skills: Recap of Our Exciting Quiz!

Congratulations on completing the Python Functions Quiz Part-2! We hope you had a blast and learned some new things.

Now that you’ve honed your skills, why not try out our other exciting Python programming quizzes? Keep exploring and leveling up your skills!

Suggested Readings

  • 30 Questions on Python List, Tuple, and Dictionary
  • Quiz on Python Functions Part I
  • Python Quiz for Beginners Part II
  • File Handling in Python Part I
  • File Handling in Python Part II
  • Basic Linux Questions and Answers

Keep up the learning momentum and stay curious!

Cheers,

TechBeamers

You Might Also Like

How to Connect to PostgreSQL in Python

Generate Random IP Address (IPv4/IPv6) in Python

Python Remove Elements from a List

Selenium Python Extent Report Guide

10 Python Tricky Coding Exercises

Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Python Functions Quiz Part-1 for Beginner Programmers Python Functions Quiz Part-1
Next Article Selenium Webdriver Download and Install Selenium Webdriver – Download and Install Stable Versions

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x