Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Extended Python Important Questions

The document provides a comprehensive collection of Python viva questions and answers, covering topics such as tuple, set, and dictionary operations, user-defined functions, classes, constructors, polymorphism, inheritance types, Pandas package operations, and Tkinter GUI basics. Each section includes specific questions with concise answers, demonstrating how to perform various operations in Python. This resource serves as a quick reference for understanding fundamental Python concepts and functionalities.

Uploaded by

forexamplet78
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)
6 views4 pages

Extended Python Important Questions

The document provides a comprehensive collection of Python viva questions and answers, covering topics such as tuple, set, and dictionary operations, user-defined functions, classes, constructors, polymorphism, inheritance types, Pandas package operations, and Tkinter GUI basics. Each section includes specific questions with concise answers, demonstrating how to perform various operations in Python. This resource serves as a quick reference for understanding fundamental Python concepts and functionalities.

Uploaded by

forexamplet78
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
You are on page 1/ 4

Python Viva Questions with Answers (Extended)

Tuple Operations

Q: How do you create a tuple in Python?

A: Use parentheses: `t = (1, 2, 3)`

Q: How can you access elements in a tuple?

A: By index, e.g., `t[0]` returns the first element.

Q: Can a tuple be converted to a list?

A: Yes, using `list(t)` and back using `tuple(l)`

Set Operations

Q: How do you create a set in Python?

A: Use curly braces: `s = {1, 2, 3}`

Q: How can you add an item to a set?

A: Using `s.add(item)`.

Q: How do you remove an item from a set?

A: Using `s.remove(item)` or `s.discard(item)`

Dictionary Operations

Q: How do you create a dictionary?

A: Using curly braces: `d = {'key': 'value'}`

Q: How do you update a dictionary?

A: By assigning new values: `d['key'] = 'new value'`

Q: How can you loop through a dictionary?

A: Using a for loop: `for key, value in d.items():`

User Defined Functions with Arguments

Q: What is a positional argument?


A: An argument passed by position, e.g., `func(10)`

Q: What is a keyword argument?

A: An argument passed by key, e.g., `func(x=10)`

Q: What is a default argument?

A: A function parameter with a default value.

User Defined Package

Q: What is a package in Python?

A: A package is a directory containing `__init__.py` and modules.

Q: How do you import a user-defined module?

A: Using `import packagename.module`

Q: What is `__init__.py` used for?

A: To mark a directory as a Python package.

Class and Object Operations

Q: How do you define a class in Python?

A: Using the `class` keyword.

Q: How do you create an object of a class?

A: By calling the class: `obj = MyClass()`

Q: How do you access a class method?

A: Using the object: `obj.method()`

Constructors in Python

Q: What is a constructor?

A: A special method `__init__()` used for initializing objects.

Q: What is a default constructor?

A: Constructor without parameters.

Q: What is a parameterized constructor?


A: Constructor that accepts arguments.

Polymorphism - Overloading and Overriding

Q: What is method overloading?

A: Defining multiple methods with same name but different parameters.

Q: What is method overriding?

A: Redefining a method in a derived class.

Q: Can Python do method overloading?

A: Python does not support traditional overloading; use default/variable arguments.

Inheritance Types

Q: What is single inheritance?

A: A class inherits from one base class.

Q: What is multiple inheritance?

A: A class inherits from multiple base classes.

Q: What is multilevel inheritance?

A: A class inherits from a derived class.

Pandas Package Operations

Q: How to create a Series from a list?

A: Using `pd.Series([1, 2, 3])`

Q: How to create a DataFrame from a dictionary?

A: Using `pd.DataFrame({'a': [1], 'b': [2]})`

Q: How do you access elements in a Series?

A: Using indexing like `series[0]`

Tkinter GUI Basics

Q: How do you create a basic Tkinter window?

A: Using `tk.Tk()`
Q: How do you set a window title in Tkinter?

A: Using `root.title('My App')`

Q: How do you start the Tkinter event loop?

A: Using `root.mainloop()`

You might also like