0% found this document useful (0 votes)
4 views3 pages

Python Basics: Comprehensive Question Bank

The document is a question bank covering various topics in Python programming, organized into four units: Python Basics, Expressions and Control Flow, Data Structures, and File Handling. It includes questions on features, syntax, data types, operators, control structures, and file operations, along with examples and explanations required for understanding Python. Each unit contains a series of questions aimed at assessing knowledge and practical skills in Python.
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)
4 views3 pages

Python Basics: Comprehensive Question Bank

The document is a question bank covering various topics in Python programming, organized into four units: Python Basics, Expressions and Control Flow, Data Structures, and File Handling. It includes questions on features, syntax, data types, operators, control structures, and file operations, along with examples and explanations required for understanding Python. Each unit contains a series of questions aimed at assessing knowledge and practical skills in Python.
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

Question Bank

UNIT – 1 : PYTHON BASICS


1. What are the main features of Python? Explain each briefly.

2. Differentiate between interactive mode and script mode in Python.

3. What is indentation in Python? Why is it important?

4. Define Python tokens. List its different types with examples.

5. What is a keyword? Give any ten Python keywords.

6. Define identifiers. Write the rules for naming identifiers.

7. What are literals? Explain different types of literals in Python.

8. What are operators? Explain arithmetic, relational, logical, and assignment


operators with examples.

9. What are variables? How are they created in Python?

10. Write a short note on comments in Python with examples.

11. Explain different number data types: integer, float, and complex with
examples.

12. What is a syntax error? Give examples.

13. What is a logical error? Give examples.

14. What is a runtime error? Give examples

UNIT – 2 : EXPRESSIONS, I/O, FLOW OF CONTROL, STRINGS


15. Explain expression and expression evaluation with examples.

16. Explain type conversion in Python with examples (implicit and explicit).

17. Describe precedence and associativity of Python operators.


18. Write a short note on identity operators: is and is not. Give examples.

19. Explain input() and print() functions with examples.

20. Explain conditional statements in Python with syntax and examples.

21. What are iterative statements? Explain for and while loops.

22. Write a Python program to find the sum of numbers using a loop.

23. What is a string in Python? How is it created?

24. Explain string slicing with examples.

25. Explain string operations: concatenation, repetition, and membership.

26. Write a program to traverse a string using a loop.

27. Explain any ten string built-in functions with examples.

UNIT – 3 : ARRAYS, LISTS, TUPLES, DICTIONARY,


MODULES, FUNCTIONS
28. What is an array? How are elements accessed in an array?

29. Write operations for adding and removing elements in an array.

30. What are lists? Explain list indexing with examples.

31. Explain any ten list methods with examples.

32. Write code to insert and remove elements at a specific position in a list.

33. What is a tuple? How is it different from a list?

34. What is a dictionary? Explain with examples.

35. Write a Python program to traverse a list using loops.

36. What is a Python module? How is it imported?

37. Explain the use of the math module with examples (pi, e, sqrt, ceil, etc.).
38. Explain functions from the random module with examples.

39. Explain functions from the statistics module with examples.

40. What are the different types of functions in Python? Explain.

41. What are arguments and parameters? Explain positional and default
parameters.

42. Explain functions returning values with examples.

43. What is recursion? Write a recursive function example (factorial/fibonacci).

44. Explain scope of variables: local vs global.

UNIT – 4 : FILE HANDLING


45. What is a file? Explain different types of files (text, binary, CSV).

46. Explain various file opening modes with examples (r, r+, w, w+, a,
a+).

47. Write a program to write data to a text file using write() and writelines().

48. Write a program to read data using read(), readline(), and readlines().

49. What is the purpose of the with statement in handling files?

50. Explain the difference between text file and binary file.

Common questions

Powered by AI

Indentation in Python is crucial because it defines the block of code instead of using braces or keywords. It affects readability by ensuring that the program's structure and flow are clear and consistent. Improper indentation leads to syntax errors and execution failures, as Python uses indentation to determine the level of grouping of statements.

Text files in Python store data in a human-readable format using characters, making them suitable for documents and source code. Binary files, however, store data in a machine-readable format, often used for images, executables, and multimedia files. Text files are preferred for logs and configuration files due to their readability, while binary files provide efficient storage and retrieval for non-textual data.

Recursion in Python allows a function to call itself to solve smaller instances of the same problem, often simplifying complex tasks. Typical use cases include sorting algorithms (like quicksort), calculating factorials, and traversing data structures (such as trees). Example: to calculate factorial(n), if n is 0, return 1; otherwise, return n * factorial(n-1). Understanding recursion helps in designing algorithms that can handle iterative processes elegantly.

Interactive mode, or REPL (Read-Eval-Print Loop), allows the immediate execution of inputs and is useful for testing small code snippets and debugging. Script mode involves writing code in a file and executing it as a program, which is beneficial for developing larger, more complex applications. Programmers may choose interactive mode for quick tests and learning, while script mode is preferred for saving code, version control, and running extensive programs.

A logical error occurs when a program compiles and runs without crashing but produces incorrect results due to a flaw in its algorithm. For instance, using a wrong logical condition in an if statement that leads to unexpected outputs. This differs from syntax errors, which are detected by the compiler due to incorrect language syntax, and runtime errors, which occur during execution and often cause the program to crash.

Python distinguishes between local and global variable scopes, which influences how variables are accessed and modified within functions. Local variables are limited to function blocks, minimizing unintended side effects and promoting modular design. Global variables can be accessed throughout a program, but if overused, they can cause dependency issues and make debugging and testing more difficult. Understanding scope is essential for designing clear, maintainable, and modular code.

The 'with' statement in Python provides a convenient way to handle files, ensuring proper acquisition and release of resources. It automatically closes the file once the block of code is exited, even if an exception occurs, which reduces the risk of resource leaks. Compared to manual file handling, which requires explicitly opening and closing files, 'with' streamlines the process, making the code cleaner and less error-prone.

Identity operators 'is' and 'is not' in Python check whether two variables point to the same object in memory, rather than if their values are equal. This is different from equality operators '==' and '!=', which compare the values themselves. Identity operato- ✔rs are crucial in scenarios where object identity matters, such as checking singleton instances or ensuring a function returns the exact object intended.

Lists in Python are mutable, meaning their elements can be changed after creation, which makes them suitable for tasks requiring modification and data storage. Tuples, on the other hand, are immutable; once created, their elements cannot be altered. They are ideal for representing fixed collections of items and as dictionary keys. Lists are used when modifications and dynamic changes are common, while tuples are used for static, read-only data.

Python follows specific rules for operator precedence and associativity to determine the order in which parts of expressions are evaluated. Precedence dictates which operations are performed first, while associativity determines the order of operations with the same precedence level. Understanding these concepts is crucial for programmers to predict how complex expressions will evaluate, ensuring accurate results and avoiding logical errors.

You might also like