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

Python VIVA

The document provides a comprehensive introduction to Python, covering its definition, key features, data types, variable rules, operators, control flow, functions, file handling, object-oriented programming, and advanced concepts. It also discusses Python libraries like NumPy and Pandas, highlighting their functionalities and advantages. Overall, it serves as a foundational guide for understanding Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python VIVA

The document provides a comprehensive introduction to Python, covering its definition, key features, data types, variable rules, operators, control flow, functions, file handling, object-oriented programming, and advanced concepts. It also discusses Python libraries like NumPy and Pandas, highlighting their functionalities and advantages. Overall, it serves as a foundational guide for understanding Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Introduction to Python

1. Define Python. What are the key features of Python?

Python is a high-level, interpreted, and general-purpose programming language with simple syntax,
making it easy to learn and use.

Features:

• Easy to read/write

• Interpreted and dynamically typed

• Object-oriented

• Extensive standard library

• Portable and platform-independent

2. What is a data type? Explain different data types in Python.

A data type represents the kind of value a variable holds.

Common data types:

• Numeric: int, float, complex

• Text: str

• Boolean: bool

• Sequence: list, tuple, range

• Set: set, frozenset

• Mapping: dict

• Binary: bytes, bytearray

• NoneType: None

3. Rules for defining a variable?

• Must start with a letter or underscore (_)

• Cannot start with a number

• Can include letters, digits, and underscores

• Cannot use reserved keywords

• Case-sensitive

4. What are different types of operators?


• Arithmetic operators: +, -, *, /, %, //, **

• Relational (comparison): ==, !=, >, <, >=, <=

• Logical: and, or, not

• Assignment: =, +=, -=, etc.

• Bitwise: &, |, ^, ~, <<, >>

• Identity: is, is not

• Membership: in, not in

5. Explain input and output function in Python.

• input(): Reads input from the user (as a string)

• print(): Displays output to the screen

6. What is the difference between is and == operators?

• ==: Checks if values are equal

• is: Checks if variables point to the same memory location (identity)

7. What is typecasting in Python?

Typecasting is converting one data type into another (e.g., string to integer using int()).

8. How does Python manage memory?

• Automatic garbage collection

• Reference counting and cyclic garbage collection

• Private heap space for memory storage

• Memory managed by Python memory manager

9. What is list? What are types of list methods?

A list is a mutable, ordered collection that allows duplicate values.

List Methods: append(), insert(), pop(), remove(), clear(), sort(), reverse(), extend(), etc.

10. What are tuples? What are types of tuple methods?

A tuple is an immutable, ordered collection.


Tuple Methods: count(), index()

11. What are sets? What are types of set methods?

A set is an unordered collection of unique elements.

Set Methods: add(), remove(), discard(), union(), intersection(), difference(), clear(), etc.

12. What is a dictionary? What are key-value pairs?

A dictionary is a collection of unordered, mutable key-value pairs. Keys are unique and immutable.

13. What is indexing?

Indexing is the method to access individual elements in sequences (like lists or strings) using their
position.

14. What is array and string?

• Array: A collection of similar data types (needs array module).

• String: A sequence of characters. Strings are immutable.

2. Control Flow and Functions

15. Explain the difference between if, elif, and else statements.

• if: Checks the first condition

• elif: Checks another condition if previous if is false

• else: Executes when all previous conditions are false

16. What is the difference between for and while loops?

• for: Used when the number of iterations is known

• while: Used when the condition must be true for looping to continue

17. What is an infinite loop? How can it be prevented?

A loop that never ends due to a condition that always evaluates to true.
Prevention: Ensure proper exit conditions or use break.

18. Explain the concept of recursion with an example.


Recursion is when a function calls itself to solve a smaller instance of the same problem. Requires a
base condition to stop.

19. Define functions. What are default arguments? What is a parameter?

• Function: A block of reusable code.

• Default Argument: A value assigned automatically if no argument is passed.

• Parameter: A variable in the function definition to accept input.

20. What is the difference between local and global variables?

• Local: Declared inside a function, used only within that function

• Global: Declared outside all functions, accessible anywhere in the program

21. Explain the return statement in Python functions.

The return statement is used to send a result back to the caller of the function and exit the function.

3. File Handling, Packaging, and Debugging

22. How do you open and read a file in Python?

Using open() function with modes like 'r' (read), and then using .read(), .readline() or .readlines()
methods.

23. What is the difference between r, w, and a modes in file handling?

• r: Read mode (file must exist)

• w: Write mode (overwrites or creates file)

• a: Append mode (adds to existing content)

24. How do you handle exceptions in Python?

Using try and except blocks to catch and handle errors during execution.

25. What are different types of errors in Python?

• Syntax Error: Mistake in code structure

• Runtime Error: Occurs during execution

• Logical Error: Code runs but gives wrong result


26. Explain try-except-else-finally blocks with an example.

• try: Write code that might throw an error

• except: Handle the error

• else: Executes if no error occurs

• finally: Always executes (used for cleanup)

27. What is the purpose of Python packages and modules?

• Modules: Single Python files with reusable code

• Packages: Collection of modules organized in directories (with __init__.py) for modular


development

28. How do you create a Python package?

• Create a folder with an __init__.py file

• Add modules (Python files) to the folder

• Import them using import package.module

4. Object-Oriented Programming (VVIMP)

29. What are classes and objects in Python?

• Class: Blueprint for creating objects

• Object: An instance of a class containing data and behavior

30. Explain encapsulation with an example. What is public, private, and protected?

Encapsulation is hiding internal data of an object.

• Public: Accessible from anywhere

• Protected: Prefix with _, accessible within class and subclasses

• Private: Prefix with __, accessible only within the class

31. What is inheritance? How does it work in Python?

Inheritance allows a class (child) to inherit properties/methods from another class (parent),
promoting code reuse.
32. What are the different types of inheritance in Python?

• Single

• Multiple

• Multilevel

• Hierarchical

• Hybrid

33. What is polymorphism? Give an example.

Polymorphism allows functions/methods to behave differently based on the context, such as same
method name behaving differently in different classes.

34. What is the difference between method overloading and method overriding?

• Overloading: Same method name with different parameters (not natively supported in
Python)

• Overriding: Redefining a method in child class that was in parent class

35. What is the difference between a class variable and an instance variable?

• Class Variable: Shared by all instances

• Instance Variable: Unique to each instance

36. What is a constructor in Python? What is a method?

• Constructor: __init__() method, initializes object state

• Method: Function defined inside a class

37. What is the significance of self in Python?

self refers to the current instance of the class and is used to access instance variables and methods.

5. Advanced Python Concepts

38. What are regular expressions? Why are they used in Python?

Regular expressions (regex) are patterns used to match strings. Used for searching, validation, or
string manipulation.
39. How do you use the re module for pattern matching?

Using functions like match(), search(), findall(), and sub() provided by the re module.

40. What are the different Python GUI frameworks?

• Tkinter: Built-in GUI toolkit

• PyQt / PySide: Feature-rich frameworks for advanced GUI

• Kivy: Used for multi-touch applications

• WxPython: Native-looking GUI apps

6. Python Libraries

41. What is NumPy?

A powerful numerical computing library in Python. Used for handling large arrays, matrices, and
mathematical operations.

42. How do you create a NumPy array?

Using numpy.array() function from the NumPy library.

43. What are the advantages of using Pandas in Python?

• Easy data manipulation and analysis

• Powerful data structures like DataFrame

• Handles missing data

• Fast operations on large datasets

44. What is Matplotlib?

A Python library used for creating static, interactive, and animated plots and visualizations.

45. What is the difference between a list and a NumPy array?

• List: General-purpose container, supports different types

• NumPy Array: More efficient, faster, supports element-wise operations, used for numerical
data

You might also like