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

Python 2mark QA

The document provides a series of 2-mark questions and answers related to Python programming. It covers fundamental concepts such as data types, variables, functions, modules, and exception handling. Additionally, it explains features like lists, tuples, dictionaries, sets, and the differences between various programming constructs.

Uploaded by

shraddha.kk22
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)
27 views2 pages

Python 2mark QA

The document provides a series of 2-mark questions and answers related to Python programming. It covers fundamental concepts such as data types, variables, functions, modules, and exception handling. Additionally, it explains features like lists, tuples, dictionaries, sets, and the differences between various programming constructs.

Uploaded by

shraddha.kk22
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

Python – 2-Mark Questions and Answers

1. What is Python?
Python is an interpreted, high-level, general-purpose programming language developed by Guido
van Rossum in 1991.

2. What are the features of Python?


• Easy to learn and use • Interpreted and dynamically typed • Object-oriented • Extensive libraries •
Cross-platform support

3. What are Python data types?


Common types: int, float, str, list, tuple, dict, set, bool.

4. What is variable in Python?


A variable is a name that refers to a value stored in memory. Example: age = 20

5. What are lists in Python?


A list is an ordered, mutable collection of elements. Example: numbers = [1,2,3,4]

6. What is tuple in Python?


A tuple is an ordered, immutable collection of elements. Example: t = (10, 20, 30)

7. What is dictionary in Python?


A dictionary is a collection of key–value pairs. Example: student = {'id':1, 'name':'Rahul'}

8. What is set in Python?


A set is an unordered collection of unique elements. Example: s = {1,2,3,4}

9. What is function in Python?


A function is a block of code that performs a specific task. Example: def add(a,b): return a+b

10. What is difference between local and global variable?


• Local variable: declared inside function, accessible only within it. • Global variable: declared
outside function, accessible throughout program.

11. What is module in Python?


A module is a file containing Python code (functions, classes, variables) that can be reused.
Example: import math

12. What is package in Python?


A package is a collection of related Python modules in a directory with __init__.py file.

13. What is difference between list and tuple?


• List: mutable, slower, [] brackets. • Tuple: immutable, faster, () brackets.

14. What are conditional statements in Python?


if, elif, else are used for decision making.

15. What are loops in Python?


Python supports for loop and while loop for repetition.

16. What is the difference between break, continue and pass?


• break: exits loop • continue: skips current iteration • pass: does nothing (placeholder)

17. What is exception handling in Python?


Python handles runtime errors using try, except, finally blocks.

18. What is difference between shallow copy and deep copy?


• Shallow copy: copies references of objects. • Deep copy: copies values recursively creating
independent objects.
19. What are Python decorators?
Decorators are functions that modify behavior of other functions or classes. Example:
@staticmethod

20. What are Python generators?


Generators are functions that use 'yield' to return an iterator, producing values one at a time.

You might also like