0% found this document useful (0 votes)
15 views2 pages

Python Interview QA

The document covers fundamental concepts of Python, including the differences between 'is' and '==', the nature of Python as an interpreted language, and the distinction between mutable and immutable data types. It also explains control flow statements, the use of *args and **kwargs in functions, and provides examples of default arguments and recursion. Additionally, it introduces lambda functions as anonymous, single-expression functions for short tasks.

Uploaded by

mohitbhadra18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Python Interview QA

The document covers fundamental concepts of Python, including the differences between 'is' and '==', the nature of Python as an interpreted language, and the distinction between mutable and immutable data types. It also explains control flow statements, the use of *args and **kwargs in functions, and provides examples of default arguments and recursion. Additionally, it introduces lambda functions as anonymous, single-expression functions for short tasks.

Uploaded by

mohitbhadra18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Python Basics & Syntax


Q: What is the difference between is and == in Python?

A: `is` checks for object identity, i.e., whether two variables point to the same object. `==` checks for

value equality.

Q: How is Python an interpreted language? What does that mean?

A: Python code is executed line by line by an interpreter, rather than being compiled into machine

code.

Q: What are Pythons data types? How do mutable and immutable types differ?

A: Python has types like int, float, str, list, tuple, dict, set. Mutable types (e.g., list, dict) can be

changed; immutable types (e.g., int, str, tuple) cannot.

Q: What is the purpose of the with statement in Python?

A: It simplifies exception handling by automatically managing resources (e.g., files) using context

managers.

Q: Explain how Python handles memory management.

A: Python uses reference counting and a cyclic garbage collector to manage memory automatically.

2. Control Flow & Functions


Q: What is the difference between break, continue, and pass?

A: `break` exits a loop, `continue` skips to the next iteration, `pass` does nothing (a placeholder).

Q: Explain *args and **kwargs in Python with an example.

A: `*args` collects extra positional arguments, `**kwargs` collects extra keyword arguments.

Example:

```python

def func(*args, **kwargs):

print(args, kwargs)

```

Q: How do default arguments work in Python functions?

A: They are assigned if no value is provided by the caller.


Example:

```python

def greet(name="World"): print(f"Hello {name}")

```

Q: Write a function to find factorial using recursion.

A: ```python

def factorial(n):

return 1 if n == 0 else n * factorial(n-1)

```

Q: What is a lambda function? When would you use it?

A: An anonymous, single-expression function. Used for short, throwaway functions.

Example: `square = lambda x: x*x`

You might also like