0% found this document useful (0 votes)
8 views5 pages

Python Q&A: Key Concepts & Examples

The document provides a comprehensive set of important questions and answers related to Python programming, divided into two sections: 2-mark questions and 16-mark questions. It covers various topics including basics, data types, functions, exceptions, and file handling. Each section includes questions that test understanding and application of Python concepts, along with detailed answers and explanations.
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)
8 views5 pages

Python Q&A: Key Concepts & Examples

The document provides a comprehensive set of important questions and answers related to Python programming, divided into two sections: 2-mark questions and 16-mark questions. It covers various topics including basics, data types, functions, exceptions, and file handling. Each section includes questions that test understanding and application of Python concepts, along with detailed answers and explanations.
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 Programming – Important Questions &

Answers

Includes 50 Two-Mark Questions with Answers & 50 Sixteen-Mark Questions

Section A: 2-Mark Questions with Answers

Unit 1: Basics & Problem Solving


Q: Define an algorithm.
A: A step-by-step procedure to solve a problem.

Q: What is the use of flowcharts?


A: To graphically represent the steps of an algorithm.

Q: What are tokens in Python?


A: Smallest units like keywords, identifiers, literals, operators, punctuation.

Q: Difference between compiler and interpreter.


A: Compiler translates whole code at once; interpreter executes line by line.

Q: What is indentation in Python?


A: Space at the beginning of a line to define code blocks.

Q: Syntax of a for loop in Python.


A: for variable in sequence:

Q: What does the break statement do?


A: Terminates the loop immediately.

Q: Define continue statement.


A: Skips current iteration and goes to next loop cycle.

Q: Output of print(10//3).
A: 3 (floor division).

Q: Difference between = and ==.


A: = is assignment; == is comparison operator.

Unit 2: Data Types, Expressions & Operators


Q: List the standard data types in Python.
A: int, float, str, bool, list, tuple, set, dict.

Q: What is dynamic typing in Python?


A: Variables can change type at runtime.
Q: Difference between list and tuple.
A: List is mutable; tuple is immutable.

Q: What is the use of len() function?


A: Returns length of a string, list, or tuple.

Q: How do you declare a dictionary in Python?


A: d = {"id":101, "name":"Ram"}

Q: What is the output of len('Python')?


A: 6

Q: Write a statement to convert a string into integer.


A: int("25")

Q: Difference between mutable and immutable data types.


A: Mutable can change (list, dict); immutable cannot (str, tuple).

Q: What is the result of 3**2?


A: 9

Q: How are comments written in Python?


A: # for single-line, ''' ''' for multi-line.

Unit 3: Functions & Modules


Q: Define a function in Python.
A: A block of code that executes when called.

Q: Global vs Local variables.


A: Global: defined outside functions; Local: inside functions.

Q: What is recursion?
A: A function calling itself.

Q: Example of a lambda function.


A: f = lambda x: x*2

Q: What is the use of return statement?


A: Sends result back from a function.

Q: What are default arguments in Python functions?


A: Parameters with default values if not passed.

Q: Differentiate between module and package.


A: Module = single file; Package = collection of modules.

Q: What is the use of import keyword?


A: To access functions/modules in Python.

Q: How do you alias a module in Python?


A: import math as m
Q: Give an example of *args in function definition.
A: def fun(*a): print(a)

Unit 4: Exceptions & Advanced Concepts


Q: What is an exception in Python?
A: An error during program execution.

Q: What is the difference between syntax error and runtime error?


A: Syntax: grammar mistakes; Runtime: errors while running.

Q: Purpose of try and except blocks.


A: To catch and handle exceptions.

Q: Use of finally block.


A: Executes always, even if exception occurs.

Q: What is a user-defined exception?


A: Custom exception created by programmer.

Q: Syntax of raise statement.


A: raise Exception("Error message")

Q: What is the output of 10/0?


A: ZeroDivisionError.

Q: What is a regular expression?


A: A pattern-matching technique for strings.

Q: Which module in Python is used for regex operations?


A: re

Q: What is the purpose of pip?


A: Python package installer.

Unit 5: Files, Iterators & Generators


Q: How do you open a file in read mode in Python?
A: f = open("[Link]","r")

Q: Syntax of read() and write() functions.


A: [Link](), [Link]('text')

Q: What is the purpose of close() in file handling?


A: To free file resources.

Q: Difference between text file and binary file.


A: Text stores characters; Binary stores bytes.

Q: What is an iterator in Python?


A: Object that produces items one by one.

Q: Purpose of __iter__() method.


A: Returns iterator object itself.

Q: What is a generator function?


A: A function that yields values using yield.

Q: What is the use of yield keyword?


A: Returns a value but retains function state.

Q: Which module in Python is used for date and time?


A: datetime

Q: Difference between w and a mode in file handling.


A: w overwrites file; a appends to file.

Section B: 16-Mark Important Questions

Unit 1: Basics & Problem Solving


Q: Define an algorithm and describe its key characteristics and importance.

Q: Explain problem-solving strategies in programming with examples.

Q: Explain control structures in Python with suitable examples.

Q: Write an algorithm to check whether a number is prime using Python.

Q: Write an algorithm for Fibonacci series (iterative and recursive).

Unit 2: Data Types & Expressions


Q: Enumerate and explain Python data types with examples.

Q: Discuss string operations in Python with examples.

Q: Explain lists, tuples, sets, and dictionaries with use cases.

Q: Explain input and output operations in Python.

Q: Write a program to check whether a number is an Armstrong number.

Unit 3: Functions & Modules


Q: Define a function in Python and explain parameters and return values.

Q: Explain recursion with examples (factorial/Fibonacci).

Q: Discuss lambda functions and their applications.

Q: Explain types of function arguments in Python with examples.

Q: Explain modular programming in Python with examples.


Unit 4: Exceptions & Advanced Concepts
Q: Define exceptions and explain exception handling in Python.

Q: Explain try, except, else, and finally blocks with examples.

Q: Explain raising built-in and custom exceptions with examples.

Q: Discuss regular expressions in Python with examples.

Q: Explain pip and module management in Python.

Unit 5: Files, Iterators & Generators


Q: Discuss file handling in Python with reading and writing examples.

Q: Explain command-line arguments in Python with an example.

Q: Explain iterators and generators with examples.

Q: Explain working with date and time in Python.

Q: Discuss data compression modules in Python.

You might also like