0% found this document useful (0 votes)
4 views

Python Concepts 4 Marks

The document defines key Python concepts such as functions, modules, and packages, along with exceptions and their types. It outlines the advantages of user-defined functions, syntax for defining functions and importing modules, and explains namespaces and predefined exceptions. Additionally, it describes recursive functions with an example.
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)
4 views

Python Concepts 4 Marks

The document defines key Python concepts such as functions, modules, and packages, along with exceptions and their types. It outlines the advantages of user-defined functions, syntax for defining functions and importing modules, and explains namespaces and predefined exceptions. Additionally, it describes recursive functions with an example.
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

Python Concepts - 4 Marks Answers

1) Define Function, module, package in python.


Function: A block of code that performs a specific task when called.
Example:
def greet():
print('Hello')

Module: A Python file (.py) containing definitions and statements.


Example: math module

Package: A collection of modules organized in directories with __init__.py file.

2) Define Exception.
An exception is an error that occurs during execution and disrupts the normal flow of the program.
Example: ZeroDivisionError, FileNotFoundError.

3) Enlist advantages of user defined function.


- Code reusability
- Easy to debug and maintain
- Improves code clarity
- Allows modular programming

4) Write syntax of user defined function.


def function_name(parameters):
# function body
return value

5) Enlist types of function arguments.


- Default arguments
- Keyword arguments
- Variable-length arguments
- Required/positional arguments

6) State use of namespace in Python


Namespace is a container where names (identifiers) are mapped to objects.
Use: Prevents name conflicts in programs.

7) Write syntax to import module in python.


import module_name
or
from module_name import function_name
Python Concepts - 4 Marks Answers

8) Define the terms i) error ii) exception


i) Error: Problems in the program that stop execution (e.g., syntax error).
ii) Exception: Runtime errors handled with try-except block.

9) List predefined exceptions in python.


- ZeroDivisionError
- IndexError
- ValueError
- FileNotFoundError
- TypeError
- KeyError

10) What is recursive function.


A function that calls itself to solve a problem.
Example:
def fact(n):
if n==1: return 1
return n * fact(n-1)

You might also like