Exit Chapter 03 · ⚙️ Working with Python Function — Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 60 0 correct so far

⚙️ Working with Python Function Quiz

Q1.

What keyword is used to define a function in Python?

Explanation

The 'def' keyword is used to define a function.

Q2.

What is the output?

def greet():
    print('Hello')

print(greet())
Explanation

greet() prints 'Hello', and print(greet()) prints the return value which is None.

Q3.

A variable declared inside a function is called:

Explanation

Variables created inside a function are local to that function.

Q4.

Which of these is a correct function call?

Explanation

Functions are called using parentheses.

Q5.

What will be the output?

def add(a,b):
    return a+b

print(add(3,2))
Explanation

The function returns 3+2 = 5.

Q6.

What happens if a function has no return statement?

Explanation

A function without return automatically returns None.

Q7.

Which is TRUE about parameters and arguments?

Explanation

Parameters are placeholders; arguments are actual values passed.

Q8.

What is the output?

def test(x):
    x = x + 1
    print(x)

test(5)
Explanation

x becomes 6 inside the function.

Q9.

Which type of arguments must be passed in correct order?

Explanation

Positional arguments depend on order.

Q10.

What is the output?

def f(a,b=3):
    return a*b

print(f(2))
Explanation

b uses default value 3, so 2*3=6.

Q11.

Default arguments must be placed:

Explanation

Required parameters must come first.

Q12.

Output?

def fun(x,y):
    print(x,y)

fun(y=2,x=5)
Explanation

Keyword arguments ignore order.

Q13.

Which of these is NOT a valid argument type?

Explanation

Python has no 'forced' argument type.

Q14.

What is returned by functions without a return statement?

Explanation

Default return is None.

Q15.

Output?

def f():
    return 1,2

print(f())
Explanation

Multiple return values form a tuple.

Q16.

What is the execution order inside a function?

Explanation

Functions follow sequential execution.

Q17.

Which statement ends function execution?

Explanation

return immediately stops the function.

Q18.

Output?

x=10
def show():
    x=5
    print(x)

show()
print(x)
Explanation

Local x=5, global x=10 remain unchanged.

Q19.

Which scope has highest priority?

Explanation

LEGB rule: Local is highest.

Q20.

Which keyword is used to modify a global variable?

Explanation

Use global variable inside function using 'global' keyword.

Q21.

Output?

def f(a,b):
    return a-b

print(f(b=5,a=8))
Explanation

8-5 = 3.

Q22.

Which call is invalid? Function: def fn(a,b=10,c=20)

Explanation

fn(1) is valid: b=10, c=20 (default).

Q23.

What is function composition?

Explanation

Composition means calling functions within other functions.

Q24.

Output?

def square(x):
    return x*x

def cube(x):
    return square(x)*x

print(cube(3))
Explanation

cube = 333 = 27.

Q25.

Which parameter receives the actual argument?

Explanation

Parameter receives the argument.

Q26.

Output?

def f(x):
    return

print(f(3))
Explanation

Empty return returns None.

Q27.

Which statement is TRUE?

Explanation

Functions promote reusability.

Q28.

Output?

x=5
def fun():
    print(x)

fun()
Explanation

Fun can access global x.

Q29.

Which belongs to LEGB rule?

Explanation

LEGB stands for Local, Enclosing, Global, Built-in.

Q30.

What is the output?

def f(n):
    n*=2
    print(n)

x=4
f(x)
print(x)
Explanation

n inside function is local; x outside remains unchanged.

Q31.

Mutating a list inside a function:

Explanation

Lists are mutable, so changes apply to caller.

Q32.

Output?

def add(lst):
    lst.append(5)

l=[1,2]
add(l)
print(l)
Explanation

List passed is modified.

Q33.

Immutable data objects include:

Explanation

Strings, ints, tuples are immutable.

Q34.

Output?

def f(a,b):
    return a/b

print(f(9,3))
Explanation

/ gives floating value.

Q35.

Which call is invalid for:

def fun(a,b,c=10): pass
Explanation

b is required, so fun(1) is invalid.

Q36.

Which type of argument assignment is this?

fun(a=3,b=5)
Explanation

Arguments are passed by keyword.

Q37.

Output?

def f(*args):
    print(args)

f(1,2,3)
Explanation

*args packs values into tuple.

Q38.

What is printed?

def f(x):
    return x*2

print(f(f(2)))
Explanation

f(2)=4; f(4)=8.

Q39.

Which is TRUE about return?

Explanation

return stops execution and sends value back.

Q40.

Output?

def show():
    pass

print(show())
Explanation

show() returns None because no return statement.

Q41.

What is recursion?

Explanation

Recursion means a function calls itself.

Q42.

Output?

def f(a,b): return a*b
print(f(a=2,b=3))
Explanation

Using keyword arguments returns 2*3=6.

Q43.

Which variable can be accessed anywhere in program?

Explanation

Global variables are accessible throughout program.

Q44.

Output?

x=10
def f():
    print(x)

f()
Explanation

Global x is printed.

Q45.

Which function header is valid?

Explanation

Correct syntax uses def f(parameters):

Q46.

Output?

def f(a,b):
    print(a,b)

f(1,b=2)
Explanation

Combination of positional and keyword.

Q47.

Which function returns absolute value?

Explanation

abs(x) returns absolute value.

Q48.

Output?

def fun(a,b,c):
    print(a+b+c)

fun(1,*(2,3))
Explanation
  • unpacks tuple into parameters.
Q49.

Which is allowed?

Explanation

Nested functions are allowed.

Q50.

Output?

def f(): return 'Hi'
print(f()+"! ")
Explanation

String concatenation gives 'Hi! '.

Q51.

Which of these is NOT a property of a function?

Explanation

Functions do not slow program; they improve structure.

Q52.

Output?

def f(a,b=2): return a*b
print(f(3, b=4))
Explanation

3*4 = 12.

Q53.

Which parameter pack stores keyword arguments?

Explanation

**kwargs collects keyword arguments into a dictionary.

Q54.

Output?

p=10
def f():
    p=20
    return p

print(f(), p)
Explanation

Local variable p=20; global p=10.

Q55.

Which is TRUE?

Explanation

Functions may return any type including lists.

Q56.

Output?

def f(): return len('Python')
print(f())
Explanation

'Python' has 6 characters.

Q57.

What does **kwargs store values as?

Explanation

Keyword arguments are stored in a dictionary.

Q58.

Output?

def f(n):
    if n>0:
        return 'Positive'

print(f(0))
Explanation

No return executed → returns None.

Q59.

Which describes a correct flow of execution?

Explanation

Function must be defined, then called, then executed.

Q60.

Output?

def outer():
    x=5
    def inner():
        return x+5
    return inner()

print(outer())
Explanation

inner() uses enclosing scope value x=5 → returns 10.