LearnFrenzy
Sign in Take a free test

Python Programming · Topic 11 of 25

Functions Questions and Concepts

  • 4 exercises
  • 50 questions
  • ~60 min
  • Answers explained

Interview Questions

Functions · Study material

Functions – Interview Questions

1. What does a function return if it has no return statement?

None.

2. What is the difference between parameters and arguments?

Parameters are the names in the function definition; arguments are the values passed in a call.

3. What are *args and **kwargs?

*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict.

4. Why are mutable default arguments dangerous?

Defaults are evaluated once when def runs, so a list or dict default is shared across calls. Use None and create the object inside.

5. Is Python pass-by-value or pass-by-reference?

Pass by object reference: the function gets a reference to the same object; mutating it is visible, rebinding is not.

6. What is the LEGB rule?

The name lookup order: Local, Enclosing, Global, Built-in.

7. Difference between global and nonlocal?

global binds a name to the module scope; nonlocal binds it to the nearest enclosing function scope.

8. What is UnboundLocalError?

Reading a local variable before it is assigned – typically count += 1 on a global without declaring global.

9. What are keyword-only arguments?

Parameters after * or *args that must be passed as name=value.

10. What does / mean in a parameter list?

Parameters before / are positional-only (Python 3.8+).

11. Can a function return multiple values?

Yes, as a tuple: return a, b.

12. What are first-class functions?

Functions are objects that can be assigned, passed as arguments, returned and stored.

13. What is a docstring?

The string literal at the start of a function, available as __doc__ and shown by help().

14. What is the order of parameter kinds?

positional-only, /, normal, *args (or *), keyword-only, **kwargs.

15. What is a closure?

An inner function that remembers variables of its enclosing function after that function has returned.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About Python Programming

Why it matters

  • Python is the most popular first language and the default for data science, AI, automation and scripting
  • Campus coding rounds and technical interviews increasingly allow – or prefer – Python
  • "Predict the output" questions on lists, strings, dictionaries and mutable defaults are a favourite in written tests
  • Clean Python with comprehensions, generators and OOP is what product companies expect from freshers

Who it is for

  • School students (Class 11–12 computer science with Python) preparing for board exams and practicals
  • College students (B.Tech, BCA, MCA, B.Sc CS) preparing for semester exams, lab work and viva
  • Freshers preparing for campus placements, coding tests and Python interviews
  • Anyone moving into data science, AI or automation who needs strong Python fundamentals

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • Topic-wise MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs: syntax errors, runtime exceptions and logical bugs
  • Coding problems with solutions and real output, every one run on Python 3 – open any example in the online Python compiler

Asked in

  • Campus placements
  • TCS, Infosys, Wipro, Accenture tests
  • Python interviews for freshers
  • Data science interviews
  • CBSE / university practicals
  • GATE CS

How to use this section

  1. Read the study material of a topic and run the examples in the browser.
  2. Practise the four exercises – MCQs, output, errors, coding problems – each marked Easy, Medium or Hard, and read every explanation.
  3. Revise with the interview questions and cheat sheet, then move to the next topic.

Search LearnFrenzy

Esc

Quick links