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

Python Programming Assignment Questions

This document is an assignment on Python programming that includes a series of questions covering various topics such as dry runs, selection statements, type conversion, and functions. It also addresses concepts like lists, tuples, dictionaries, regular expressions, and exception handling. The assignment aims to test the understanding of fundamental Python programming concepts and their applications.

Uploaded by

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

Python Programming Assignment Questions

This document is an assignment on Python programming that includes a series of questions covering various topics such as dry runs, selection statements, type conversion, and functions. It also addresses concepts like lists, tuples, dictionaries, regular expressions, and exception handling. The assignment aims to test the understanding of fundamental Python programming concepts and their applications.

Uploaded by

ashwinpunmagr99
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Programming

Assignment no.1

1. What is dry run in Python?

2. Give the purpose of selection statements in Python.

3. List the types of type conversion in Python.

4. What is the use of pass statement?

5. Explain the function enumerate( ).

6. Explain the extend method of list.

7. What are required arguments in function?

8. Explain any 2 functions in time module.

9. What are the types of file in Python?

10. Write the use of seek & tell function.

11. What are the advantages of Python?

12. List out main differences between lists & tuple.

13. Python is a scripting language. Comment.

14. Demonstrate set with example.

15. What is dictionary? Give example.

16. What is regEx? give example.

17. What is user defined Module? Give example.

18. Python is case sensitive language. Comment.

19. What is lambda function? Give example.


20. How to handle exception in Python?

21. Explain any 2 meta characters used in regular expression.

22. Explain any 2 built-in list functions.

23. Explain backward indexing in strings.

24. Define identifiers.

25. What is the use of seek ( ) & tell ( ) functions?

26. Demonstrate list slicing.

26. A tuple is ordered collection of items. Comment.

27. Write a short note on datatypes in Python.

28. Write a short note on exception handling.

29. What is a module? What is package? Explain with example.

30. What are lists and tuples? What is the key difference between the two?

Common questions

Powered by AI

Python's advantages include its simplicity, readability, and an extensive standard library which fosters quick and efficient development. This readability makes it easier to learn for beginners. Python is dynamically typed and supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Its interoperability and open-source community provides robust support and a wealth of libraries for fields ranging from web development to data science, making it versatile for varied applications .

Selection statements in Python, such as if, elif, and else, allow programmers to execute certain parts of code based on conditions. These statements are crucial for implementing the logic that modifies the program's execution path, enabling decision-making. For instance, using an if statement, a program can execute a block of code only if a particular condition (e.g., x > 10) is true, which is essential for tasks like validating user inputs or controlling game loops .

Python is considered a scripting language because it is interpreted, meaning the code is executed line-by-line at runtime, which eases debugging and development. This is different from compiled languages where the code is transformed into machine code before execution. As interpreted, Python offers flexibility and ease of use, which suits rapid application development and scripting tasks. However, this can result in slower execution times compared to compiled languages. Python's use of Just-In-Time compilation (via implementations like PyPy) can address some performance concerns .

The pass statement in Python acts as a placeholder where syntactically some code is expected but no code is to be executed. It's often used during the development phase to allow the coder to structure the program and insert empty loops, functions, or conditionals which will be filled with code later. This helps avoid compilation errors for incomplete sections of code and is useful when debugging or iterating layout stages of project design .

Lists and tuples are both sequence data types in Python. Lists are mutable, meaning their elements can be changed after creation, making them suitable for collections of items that may need modification. Tuples, on the other hand, are immutable, which can lead to performance optimizations. Due to immutability, tuples are often used for fixed data structures or records. If integrity and safety from modifications are required, tuples are preferred. Lists are more appropriate for scenarios where data may frequently change .

User-defined modules in Python facilitate code organization and reuse by encapsulating reusable functions, classes, and variables into separate files. This modular approach not only keeps codebases cleaner and more manageable but also allows for easier maintenance. For example, creating a module `math_utils.py` with utility functions for mathematical operations enables reuse across projects without rewriting them. It fosters collaborative development by allowing different teams to work on separate modules and later integrate them into larger projects .

Regular expressions (regEx) in Python are sequences of characters that define search patterns, primarily used for string matching and manipulation. They enable powerful text-search capabilities, allowing for complex query expressions. For instance, `import re; re.match(r'\d+', '123abc')` uses `\d+` to match one or more digits in a string, effectively extracting numbers from text data. They are invaluable for validating formats, such as email or phone numbers, across various applications including data cleaning and web scraping .

Lambda functions in Python are small anonymous functions defined using the lambda keyword. They can have any number of input parameters but contain only one expression. These functions contribute to Python's higher-order, functional programming capabilities by allowing users to create concise, throwaway functions on-the-fly for operations like filtering and mapping without needing a formal function definition. For example, `lambda x: x + 1` increments a number by one and can be utilized in functional tools like map and filter to process lists efficiently .

Backward indexing in Python allows access to string elements from the end towards the beginning, using negative indices. For example, with a string `s = 'Python'`, `s[-1]` refers to the last character 'n', while `s[-2]` refers to 'o'. This feature is particularly useful for accessing elements from the end without calculating their forward index. It's often used in scenarios where reverse order access or manipulations are needed, such as checking for palindromes .

Two built-in functions in Python's time module are `time()` and `sleep()`. The `time()` function returns the current time in seconds since the epoch (January 1, 1970, 00:00:00 (UTC)), which is useful for measuring time intervals. The `sleep(seconds)` function delays the program execution for the specified amount of time, which is handy in situations requiring time-dependent tasks like simulating a delay in web requests or throttling execution speed to control API rates .

You might also like