PFE viva questions
PFE viva questions
= 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
What are control flow statements? Explain if, elif, else, for, and while loops with
examples.
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 built-in functions in Python? Give examples of some commonly used ones
(e.g., print(), len(), type(), input(), range()).
Lists:
How do you create a list?- list=[1,2,3]
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)
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 some common set operations? (e.g., union, intersection, difference)-
III. Functions:
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: