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

Python Viva

Python is a high-level, interpreted, and versatile programming language introduced by Guido van Rossum in 1991. Key features include its easy readability, extensive standard library, and support for multiple programming paradigms. The document covers various aspects of Python, including data types, functions, exception handling, and loops.

Uploaded by

rithvikarala02
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 views8 pages

Python Viva

Python is a high-level, interpreted, and versatile programming language introduced by Guido van Rossum in 1991. Key features include its easy readability, extensive standard library, and support for multiple programming paradigms. The document covers various aspects of Python, including data types, functions, exception handling, and loops.

Uploaded by

rithvikarala02
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
You are on page 1/ 8

Q: Who introduced Python?

A: Python was introduced by Guido van Rossum in 1991. He developed it as a high-level, easy-to-read, and versatile
programming language.

Q2: What type of language is Python?


A: Python is a high-level, interpreted, general-purpose, object-oriented, and dynamically typed language.

Q: Define indentation in Python.

A:
Indentation in Python refers to the spaces or tabs at the beginning of a line that define the block of code. Unlike
many other programming languages that use curly braces {} to mark code blocks, Python uses indentation to
group statements.

Q3: What are Python's key features?


A:

 Easy to learn and read


 Interpreted language
 Dynamically typed
 Extensive standard library
 Supports object-oriented, procedural, and functional programming
 Open-source and cross-platform

Q5: What are Python's data types?


A:

 Numeric: int, float, complex


 Sequence: list, tuple, range, string
 Set: set, frozenset
 Mapping: dict
 Boolean: bool
 None: NoneType


 Q: What is an operator in Python?
 A:
An operator in Python is a symbol that performs a specific operation on one or more operands (values or
variables). Operators are used to perform operations like addition, subtraction, comparison, logical
operations, etc.
Q6: What is the difference between a list and a tuple?
A:

 List: Mutable (can change), written with square brackets [].


 Tuple: Immutable (cannot change), written with parentheses ().

Q7: What is indentation in Python?


A: Python uses indentation (whitespace) to define code blocks. It replaces curly braces used in other languages.

Intermediate Level

Q8: What is a function in Python?


A: A function is a reusable block of code that performs a specific task. Defined using def keyword.

**Q9: What are *args and kwargs?


A:

 *args allows passing a variable number of positional arguments.

Q12: What is exception handling in Python?


A: Exception handling is done using try, except, finally blocks to catch and handle errors.

Q: Define list in Python.

A:
A list in Python is an ordered, mutable (changeable) collection of items. Lists can store elements of different data
types such as integers, strings, or even other lists. Lists are defined using square brackets [].

 Lists support indexing, slicing, and many built-in methods (like append(), remove(), sort(), etc.).
 Q: Define tuple in Python.
 A:
A tuple in Python is an ordered, immutable (unchangeable) collection of items. Tuples can store elements
of different data types. Once a tuple is created, its elements cannot be modified. Tuples are defined using
parentheses ().
 Tuples support indexing and slicing but do not allow item assignment or modification.
 : Define dictionary in Python.
 A:
A dictionary in Python is an unordered collection of key-value pairs. Each key in a dictionary is unique,
and each key maps to a value. Dictionaries are mutable, which means you can change, add, or remove
items. Dictionaries are defined using curly braces {}.
  Keys must be immutable (e.g., strings, numbers, tuples).
  Values can be of any data type.
 Q1: What is a module in Python?
 A:
A module is a file containing Python code (functions, classes, variables) that can be imported and reused
in other Python programs. It helps in code organization and reusability.
Example: math, os, sys are built-in modules.

 Q2: How do you create a module in Python?


 A:
Simply create a Python file (e.g. my_module.py) containing functions or variables. You can import it
using:
 python
 CopyEdit
 import my_module
 Q6: What is an exception in Python?
 A:
An exception is an error that occurs during the execution of a program, which interrupts the normal flow
of instructions.

 Q7: How do you handle exceptions in Python?


 A:
Using try-except blocks:
 python
 CopyEdit
 try:
 # risky code
 except ExceptionType:
 # handling code

1: What is a function in Python?

A:
A function is a reusable block of code that performs a specific task. It helps to divide a program into small,
manageable parts.

Q2: How do you define a function in Python?

A:
Using the def keyword:

python
CopyEdit
def function_name(parameters):
# function body
return result
Q3: What is the difference between built-in functions and user-defined functions?

A:

 Built-in functions: Predefined in Python (e.g., len(), print(), max()).


 User-defined functions: Created by the programmer using def.

Q4: What are arguments and parameters?

A:

 Parameter: The variable listed inside the function definition.


 Argument: The value passed to the function when calling it.

Q1: What is GUI in Python?

A:
GUI (Graphical User Interface) allows users to interact with applications visually using buttons, menus, text
boxes, etc., instead of typing commands. Python provides several libraries to create GUI applications.

Q2: Name some Python libraries used for GUI development.

A:

 Tkinter (built-in)
 PyQt / PySide
 Kivy
 wxPython

Q3: What is Tkinter?

A:
Tkinter is Python’s standard built-in GUI library. It provides tools to create windows, labels, buttons, text fields,
etc., easily.

Q6: What is event-driven programming?

A:
In GUI, event-driven programming means the program waits for user actions (events) and responds
accordingly (e.g., clicking a button triggers a function).
Q: Define range() function in Python.

A:
The range() function in Python returns a sequence of numbers. It is commonly used in loops to iterate a specific
number of times.

Syntax:

python
CopyEdit
range(start, stop, step)

 start (optional): starting value (default is 0)


 stop: end value (not included)
 step (optional): increment (default is 1)

Q: Define array in Python.

A:
An array is a collection of items stored at contiguous memory locations. It is used to store multiple items of the
same data type together.

In Python, we usually use lists instead of arrays for most purposes. But if we need arrays (with better
performance for large numeric data), we can use:

 array module (standard library)



 Q: Define string in Python.
 A:
A string in Python is a sequence of characters enclosed in single quotes ' ', double quotes " ", or triple
quotes ''' ''' / """ """.
Strings are immutable — once created, they cannot be changed.
 Example:
 python
 CopyEdit
 s = "Hello World"

 ✅ Q: What are is methods in Python strings?


 A:
Python string methods that start with is are Boolean methods. They check certain conditions and return
True or False.
 Here are some common is methods:
Method Description Example
isalpha() Returns True if all characters are letters "abc".isalpha() ➔ True
isdigit() Returns True if all characters are digits "123".isdigit() ➔ True
isalnum() Returns True if all characters are letters or digits "abc123".isalnum() ➔ True
islower() Returns True if all characters are lowercase "abc".islower() ➔ True
isupper() Returns True if all characters are uppercase "ABC".isupper() ➔ True
isspace() Returns True if string contains only whitespace " ".isspace() ➔ True
istitle() Returns True if string is title case "Hello World".istitle() ➔ True

Q1: What is a loop in Python?

A:
A loop is used to execute a block of code repeatedly as long as a condition is true.

Q2: What types of loops are available in Python?

A:
Python supports two main types of loops:

 for loop
 while loop

Q3: Explain the for loop in Python.

A:
The for loop is used to iterate over a sequence (like list, tuple, string, or range).

Example:

python
CopyEdit
for i in range(5):
print(i)

Q4: Explain the while loop in Python.

A:
The while loop continues to execute as long as the condition is true.

Example:
python
CopyEdit
i = 0
while i < 5:
print(i)
i += 1

Q5: What is the difference between for and while loop?

forloop while loop


Used when number of iterations is known Used when condition depends on runtime
Iterates over sequences Uses condition checking

Q6: What is break statement?

A:
break is used to exit the loop prematurely when a certain condition is met.

Example:

python
CopyEdit
for i in range(10):
if i == 5:
break
print(i)

Q7: What is continue statement?

A:
continue skips the current iteration and moves to the next iteration.

Example:

python
CopyEdit
for i in range(5):
if i == 2:
continue
print(i)

Q8: What is else with loop?

A:
The else block after a loop executes when the loop completes normally (without break).
Example:

python
CopyEdit
for i in range(3):
print(i)
else:
print("Loop finished")

Q9: Can we use loops inside loops (nested loops)?

A:
Yes, we can use loops inside another loop.
Example:

python
CopyEdit
for i in range(3):
for j in range(2):
print(i, j)

Q10: What is an infinite loop?

A:
A loop that never ends because its condition always remains true.
Example:

python
CopyEdit
while True:
print("Infinite")

You might also like