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

Python Lab Viva Questions Guide

The document contains a comprehensive list of practical questions for a Python lab viva, organized into ten practical sessions. Each session includes various questions covering key Python concepts such as data types, operators, functions, and programming constructs. The questions aim to assess the understanding and application of Python programming skills.
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)
23 views4 pages

Python Lab Viva Questions Guide

The document contains a comprehensive list of practical questions for a Python lab viva, organized into ten practical sessions. Each session includes various questions covering key Python concepts such as data types, operators, functions, and programming constructs. The questions aim to assess the understanding and application of Python programming skills.
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

ARYA Institute of Engineering Technology and Management

Python Lab Viva Questions


Practical No. 1

Q.1. what are the key features of Python?

Q.2. Differentiate between lists and tuples.

Q.3. Explain the ternary operator in Python.

Q.4. What are negative indices?

Q.5. Is Python case-sensitive?

Q.6. How long can an identifier be in Python?

Q.7. How would you convert a string into lowercase ?

Q.8. What is the pass statement in Python?

Practical No. 2

Q.1. Explain help() and dir() functions in Python.

Q.2. How do you get a list of all the keys in a dictionary?

Q.3. What is slicing?

Q.4. How would you declare a comment in Python?

Q.5. How will you check if all characters in a string are alphanumeric?

Q.6. How will you capitalize the first letter of a string?

Q.7. We know Python is all the rage these days. But to be truly accepting of a great
technology, you must know its pitfalls as well. Would you like to talk about this?
Q.8. With Python, how do you find out which directory you are currently in?

Practical No. 3

Q.1. How do you insert an object at a given index in Python?

Q.2. And how do you reverse a list?


Q.3. And how do you reverse a list?

Q.4. What is the Python interpreter prompt?


Q.5. How does a function return values?
Q.6. How would you define a block in Python?
Q.7. Why do we need break and continue in Python?
Q.8. Will the do-while loop work if you don’t end it with a semicolon?
Q.9. In one line, show us how you’ll get the max alphabetical character from a string.

Practical No 4.

Q.1. What is Python good for?


Q.2. Can you name ten built-in functions in Python and explain each in brief?
Q.3. What will the following code output?
Q.4. How will you convert a list into a string?
Q.5. How will you remove a duplicate element from a list?
Q.6. Can you explain the life cycle of a thread?.
Q.7. What is a dictionary in Python?
Q.8. Explain the //, %, and ** operators in Python.

Practical No. 5

Q.1. What do you know about relational operators in Python.


Q.2. What are assignment operators in Python?
Q.3. Explain logical operators in Python.
Q.4. What are membership operators?
Q.5. Explain identity operators in Python.
Q.6. Finally, tell us about bitwise operators in Python.
Q.7. What data types does Python support?
Q.8. What is a docstring?

Practical No. 6

Q.1. How would you convert a string into an int in Python?


Q.2. How do you take input in Python?
Q.3. What is a function?
Q.4. What is recursion?
Q.5. What does the function zip() do?
Q.6. How do you calculate the length of a string?
Q.7. Explain Python List Comprehension.
Q.8. How do you get all values from a Python dictionary?
Practical No. 7

Q.1. What if you want to toggle case for a Python string?


Q.2. Write code to print only upto the letter t.
Q.3. Write code to print everything in the string except the spaces.
Q.4. Now, print this string five times in a row.
Q.5. What is the purpose of bytes() in Python?
Q.6. What is a control flow statement?
Q.7. Create a new list to convert the following list of number strings to a list of numbers.
nums=[‘22’,’68’,’110’,’89’,’31’,’12’]
Q.8. Given the first and last names of all employees in your firm, what data type will
you use to store it?

Practical No. 8

Q.1. How would you work with numbers other than those in the decimal number
system?
Q.2. What does the following code output?
Q.3. How many arguments can the range() function take?
Q.4. What is PEP 8?
Q.5. How is Python different from Java
Q.6. What is the best code you can write to swap two numbers?
Q.7. How can you declare multiple assignments in one statement?
Q.8. If you are ever stuck in an infinite loop, how will you break out of it?

Practical No. 9

Q.1. How do we execute Python?


Q.2. Explain Python’s parameter-passing mechanism.
Q.3. What is the with statement in Python?
Q.4. How is a .pyc file different from a .py file?
Q.5. What makes Python object-oriented?
Q.6. How many types of objects does Python support?

Practical No. 10

[Link] is it called Python?


[Link] is the interpreter in Python?
[Link] does a python do?
[Link] is the purpose of PYTHONHOME environment variable?
[Link] is the purpose of PYTHONCASEOK environment variable?
[Link] is the purpose of PYTHONSTARTUP environment variable?
[Link] is the purpose of PYTHONPATH environment variable?
[Link] given the first and last names of bunch of employees how would you store it and
what datatype?

Common questions

Powered by AI

Lists and tuples are fundamental data structures in Python that reflect its philosophy of simplicity and versatility. Lists are mutable, allowing modifications to the sequence of elements such as adding, removing, or altering items, which is ideal for managing collections of items where the dataset changes over time. Tuples, however, are immutable, meaning their length and elements cannot be changed after assignment; this immutability makes tuples suitable for fixed collections of items or use as keys in dictionaries. This dichotomy demonstrates Python’s design philosophy of choosing the right tool for the right task. The ease of use, combined with powerful built-in methods for both lists and tuples, exemplifies Python's emphasis on ease of coding and readability .

Python’s membership operators, in and not in, enhance string manipulation and data validation by allowing concise and readable expressions to check for the presence or absence of a substring within a string or an element within a collection. For string manipulation, these operators enable quick tests of containment, significantly simplifying tasks like input validation, substring detection, and filtering. As such, they help identify if specific values exist within datasets or strings without having to write verbose loops or conditional statements, enhancing both code readability and efficiency .

Python’s dynamic typing system, where a variable’s type is determined at runtime, directly impacts software testing practices by necessitating a stronger emphasis on runtime testing rather than compile-time checks. This flexibility allows rapid development and prototyping, but increases the potential for type-related runtime errors that are not caught in earlier development stages. Consequently, developers rely more heavily on unit tests and integration tests that execute the code to catch errors. Dynamic typing can lead to fewer constraints and simpler code syntax but also demands comprehensive test coverage to ensure reliability and correctness of the software, potentially increasing the scope and complexity of test suites .

Python functions can effectively demonstrate recursion by implementing classical examples such as the calculation of factorial numbers, Fibonacci series, or tree traversals. A recursive function is one that calls itself with a different argument until it reaches a base case, making it an ideal conceptual tool for problems that can be divided into smaller, similar sub-problems. For example, a factorial function multiplies the current number by the factorial of the previous number, eventually reaching the base case of factorial 0 or 1. Recursive functions in Python, by clearly defining the base case and the recursive case, allow for a natural expression of iterative processes, while demonstrating efficiency and clarity in code logic .

PEP 8 provides style guidelines, or conventions, for writing Python code. Its role in Python development is to promote uniformity and readability among different code projects, facilitating collaboration and code maintenance. Adherence to PEP 8 enhances code clarity and reduces the cognitive load required to understand and modify code bases, particularly in collaborative environments. The guidelines address various aspects such as naming conventions, indentation, and code layout, helping ensure that Python code is not only syntactically correct but also aesthetically coherent and maintainable. Following PEP 8 can prevent misunderstandings and errors that arise from inconsistent coding styles, ultimately enhancing productivity and code quality across projects .

The pass statement in Python acts as a placeholder in the control flow and has several implications. It allows the programmer to write syntactically correct minimal code structures when planning future implementations or when a particular block of code is not needed yet. In debugging, it may intentionally prevent syntax errors when the code is incomplete, allowing the program to pass over a block without executing any operations, thereby maintaining the program’s flow. However, excessive use of pass in mature code might indicate an unfinished implementation or improper handling of control flow, leading to potential logical errors. It reflects Python’s philosophy of readability and coding style by allowing developers to incrementally build out their programs .

The with statement in Python, commonly used with file operations, simplifies resource management by ensuring that resources are properly acquired and released. When using the with statement to open files, it automatically closes the file when the block is exited, either normally or via an exception. This reduces the chance of errors such as forgetting to close files or handling exceptions properly. In contrast, traditional file opening requires explicit calls to open() and close(), which increases the chance of resource leaks or unhandled exceptions if not carefully managed. The with statement streamlines code readability, maintains resource integrity, and aligns with Python’s emphasis on clean and efficient code .

Python offers several advantages over Java, including simpler syntax which makes the code easier to read and write. This often leads to faster development times. Python is dynamically typed, which can speed up debugging and prototyping. Additionally, Python’s rich set of libraries and frameworks facilitates rapid development of complex applications. However, Python is generally slower than Java due to its dynamic nature, which might be a disadvantage for CPU-intensive applications. Java’s statically typed nature and better performance in execution times make it more suitable for high-performance applications and enterprise-level software that require type safety and robustness. These differences impact software development by affecting the choice of language based on project requirements like execution speed versus development speed, maintainability, and scalability .

Storing employee names would most appropriately be done using a list of dictionaries if additional employee information (such as department, position) is needed alongside names. Each dictionary could hold key-value pairs for the employee’s first name, last name, and any other details. This structure allows convenient access and manipulation of individual employee records and makes it easy to implement additional functionalities like searching and sorting. Lists provide iteration over records, while dictionaries within the list encapsulate each employee’s full data. If only names are needed and no additional information is required, a simple list or set might suffice, with a set providing unique name storage and ensuring no duplicates .

The zip() function in Python is a powerful tool for handling and transforming data by aggregating elements from two or more iterables (like lists), creating pairs of elements. It proceeds until the shortest input iterable is exhausted and returns an iterator of tuples. This function is often used in parallel iteration, data transformation, and combining datasets, such as merging two lists element-wise or creating column-row transformation in data structures. This facilitates data handling by allowing parallel processing of datasets, thus making Python efficient for tasks involving data correlation and visualization .

You might also like