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

PFE viva questions

The document provides an overview of Python, including its key features, data types, and the differences between mutable and immutable types. It explains variable declaration, operators, control flow statements, and the importance of comments and indentation. Additionally, it covers data structures like lists, tuples, dictionaries, and sets, as well as functions, file handling, modules, exception handling, and advanced topics 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 TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

PFE viva questions

The document provides an overview of Python, including its key features, data types, and the differences between mutable and immutable types. It explains variable declaration, operators, control flow statements, and the importance of comments and indentation. Additionally, it covers data structures like lists, tuples, dictionaries, and sets, as well as functions, file handling, modules, exception handling, and advanced topics 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 TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

What is Python? What are its key features and advantages?

= readability ,
versatility

What are the different data types in Python? (e.g., integers, floats, strings,
booleans, lists, tuples, dictionaries, sets) Give examples.

Explain the difference between mutable and immutable data types. Which Python types
fall into each category?- list-mutable, tuple-immutable, set-mutable, dictionary-
mutable

How do you declare variables in Python? What are the naming conventions?= assign
value to name, contains digits, letters , underscores, cant start with number, case
sensitive

Explain the use of operators in Python (arithmetic, comparison, logical,


assignment, bitwise). Give examples. logical- and= return if both are true, or=
returns true if one is true, not= return true if it is false and vice versa

What are control flow statements? Explain if, elif, else, for, and while loops with
examples.

How do you write comments in Python? Why are they important?

What is indentation in Python? Why is it crucial?= space to define code blocks

Explain the difference between == and is.- == (Equality Operator)- compares values
of two objects, is (Identity Operator)- check if two variables refers to same
object

What are the different ways to format strings in Python? (e.g., f-


strings, .format(), %)

How do you take user input in Python?

What are the built-in functions in Python? Give examples of some commonly used ones
(e.g., print(), len(), type(), input(), range()).

II. Data Structures:

Lists:
How do you create a list?- list=[1,2,3]

How do you access elements in a list? (indexing, slicing)-print(list[1])

How do you add, remove, or modify elements in a list? (append, insert, remove, pop,
etc.)- list.append(), list.insert(), pop removes item from specified index, remove-
removes the first occurrence of a specified value from the list.

What are list comprehensions? Give an example.- define and create lists based on
existing lists.= list comprehension is way to create new list based on existing
iterables
numbers = [1, 2, 3, 4, 5]
squares = [x**2 for x in numbers]
print(squares) # Output: [1, 4, 9, 16, 25]

What are some common list methods? (e.g., sort(), reverse(), index(), count())-

Tuples:
How do you create a tuple?- tup=(1,2,3)/ tup=1,2,3 print(tuple(tup))
What is the key difference between lists and tuples?- list=mutable tuple not,
list[], tuple()

When are tuples preferred over lists? sequence must not be changed use tuple

Dictionaries:
How do you create a dictionary? dict1={1:'a', 2:'b', 3:'c'} print(dict1)

How do you access values in a dictionary? print(dict.get(1))

How do you add, remove, or modify key-value pairs in a dictionary? To add-


dict['city']='america' print(dict) , to remove- del dict ['1'] print[dict]

What are dictionary comprehensions?

What are some common dictionary methods? (e.g., keys(), values(), items(), get())

Sets:
How do you create a set? set= {1,2,3, } print(set)

What are the key properties of sets? (unordered, unique elements)

What are some common set operations? (e.g., union, intersection, difference)-

III. Functions:

What is a function? Why are they used? -


How do you define a function in Python? (using def)
What are parameters and arguments?
What is the difference between positional and keyword arguments?
What is the return value of a function?
What is the scope of a variable? (local, global)
What are lambda functions? Give an example of when you might use one.
What are decorators? (A more advanced topic)
What are generators? (A more advanced topic)
IV. Object-Oriented Programming (OOP):

V. File Handling:

How do you open and close files in Python? (using open() and close() or with
open(...))
How do you read and write data to files?
What are the different file modes? (e.g., 'r', 'w', 'a', 'rb', 'wb')
How do you handle exceptions related to file I/O? (using try...except)
VI. Modules and Packages:

What is a module? How do you import modules in Python? (using import, from ...
import)
What is a package?
How do you install external packages? (using pip)
What are some commonly used Python libraries? (e.g., NumPy, Pandas, Matplotlib,
requests) Be prepared to discuss specific libraries you've used.
VII. Exception Handling:

What are exceptions? Why are they important?


How do you handle exceptions in Python? (using try...except, finally)
What are some common exceptions in Python? (e.g., TypeError, ValueError, IOError,
IndexError, KeyError)
VIII. Advanced Topics (Depending on the level):

What are iterators and generators?


What are decorators?
What are context managers? (using with)
What is multithreading/multiprocessing?
What are regular expressions? (using the re module)
What are some best practices for writing Python code? (PEP 8)
How do you debug Python code?
What are some common Python frameworks for web development? (e.g., Django, Flask)
What are some common Python libraries for data science? (e.g., NumPy, Pandas,
Scikit-learn)
IX. "Why" Questions (These test understanding, not just memorization):

You might also like