0% found this document useful (0 votes)
5 views4 pages

Viva Questions Python

The document provides a comprehensive set of questions and answers related to Python programming, covering topics such as basic operations, functions, strings, lists, tuples, dictionaries, file handling, and libraries like JSON, NumPy, and Pandas. Each section includes specific queries about concepts and methods, along with concise explanations. It serves as a study guide for understanding fundamental Python programming concepts and operations.

Uploaded by

mahesh
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)
5 views4 pages

Viva Questions Python

The document provides a comprehensive set of questions and answers related to Python programming, covering topics such as basic operations, functions, strings, lists, tuples, dictionaries, file handling, and libraries like JSON, NumPy, and Pandas. Each section includes specific queries about concepts and methods, along with concise explanations. It serves as a study guide for understanding fundamental Python programming concepts and operations.

Uploaded by

mahesh
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

VIVA QUESTIONS & ANSWERS – PYTHON PROGRAM LAB

UNIT–1 : Basic Python Programs & Operators


1. Largest of Three Numbers
Q1. How do you find the largest of three numbers in Python?
A. By using conditional statements (if-elif-else) or the built-in max() function.
Q2. Why do we compare numbers using relational operators?
A. To determine relationships like greater than, less than, or equality.

2. Prime Numbers
Q3. What is a prime number?
A. A number greater than 1 that has only two factors: 1 and itself.
Q4. How do you check whether a number is prime?
A. By checking divisibility from 2 to √n.

3. Swapping Without Temporary Variable


Q5. How can two numbers be swapped without a temporary variable in Python?
A. Using tuple unpacking: a, b = b, a.
Q6. Why does Python allow swapping in one line?
A. Because Python supports multiple assignment.

4. Python Operators
Q7. What are arithmetic operators?
A. Operators used for mathematical calculations (+, -, *, /, %).
Q8. What is the difference between relational and logical operators?
A. Relational operators compare values, logical operators combine conditions.
Q9. What is a ternary operator?
A. A conditional expression written in one line:
x if condition else y.
Q10. What are membership operators?
A. in and not in, used to test sequence membership.
Q11. What are identity operators?
A. is and is not, used to compare memory locations.

5. Complex Numbers
Q12. How are complex numbers represented in Python?
A. In the form a + bj, where j is the imaginary unit.
Q13. Can Python perform arithmetic on complex numbers?
A. Yes, Python supports addition, subtraction, multiplication, and division.

6. Multiplication Table
Q14. Which loop is best suited for printing multiplication tables?
A. for loop.
UNIT–2 : Functions, Strings & Lists
1. Multiple Return Values
Q15. How can a function return multiple values in Python?
A. By returning a tuple.
Q16. Is tuple packing automatic in Python?
A. Yes.

2. Default Arguments
Q17. What are default arguments?
A. Function parameters with predefined values.
Q18. Why are default arguments useful?
A. They reduce function calls and improve flexibility.

3. String Length Without Library


Q19. How do you find string length without len()?
A. By iterating through characters and counting.

4. Substring Check
Q20. How can you check if a substring exists in a string?
A. Using in operator.

5. List Operations
Q21. What is list insertion?
A. Adding an element at a specific index using insert().
Q22. What is slicing in lists?
A. Extracting a portion of a list using [start:end].

6. Built-in List Functions


Q23. Name any five list built-in functions.
A. append(), remove(), sort(), reverse(), len().

UNIT–3 : Tuples, Strings & Dictionaries


1. Tuple Concatenation
Q24. Are tuples mutable?
A. No, tuples are immutable.
Q25. How can tuples be concatenated?
A. Using + operator.

2. Vowel Count (No Control Flow)


Q26. How can vowels be counted without loops?
A. Using count() method for each vowel.
3. Key Existence in Dictionary
Q27. How do you check if a key exists in a dictionary?
A. Using in keyword.

4. Add Key-Value Pair


Q28. How do you add a new element to a dictionary?
A. dict[key] = value.

5. Sum of Dictionary Values


Q29. How do you sum dictionary values?
A. Using sum([Link]()).

UNIT–4 : Files, Arrays, Matrices & OOP


1. File Sorting
Q30. Why convert text to lowercase while writing to file?
A. To maintain uniformity and avoid case sensitivity.

2. Reverse File Lines


Q31. How do you reverse a string in Python?
A. Using slicing [::-1].

3. File Statistics
Q32. How do you count words in a file?
A. By splitting each line using split().

4. Array Operations
Q33. Which module is used for arrays in Python?
A. array module.

5. Matrix Operations
Q34. What is matrix transpose?
A. Converting rows into columns.

6. OOP – Shapes
Q35. What is a class?
A. A blueprint for creating objects.
Q36. What is inheritance?
A. Acquiring properties of a parent class.

UNIT–5 : JSON, NumPy, Pandas & Matplotlib


1. JSON
Q37. What is JSON?
A. JavaScript Object Notation, used for data exchange.
Q38. How do you identify a complex JSON object?
A. By checking for nested structures.

2. NumPy Arrays
Q39. What is NumPy?
A. A library for numerical computing.
Q40. What does ndim represent?
A. Number of dimensions of an array.
Q41. What is dtype?
A. Data type of array elements.

3. Indexing & Slicing


Q42. What is Boolean indexing?
A. Selecting elements based on conditions.

4. Array Operations
Q43. What is cumulative sum?
A. Running total of array elements.

5. Pandas DataFrame
Q44. What is a DataFrame?
A. A 2-D labeled data structure.
Q45. What does head() do?
A. Displays first five rows.

6. Matplotlib
Q46. What is a scatter plot?
A. A graph showing relationship between two variables.
Q47. Why is matplotlib used?
A. For data visualization.

You might also like