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

Essential Python Viva Questions Guide

The document lists important viva questions related to Python programming, covering topics such as language translation, data types, functions, file handling, and error types. It provides concise answers to each question, explaining concepts like mutable vs immutable types, slicing, comments, variable scope, and file operations. Additionally, it discusses the significance of stack operations and exceptions in Python.

Uploaded by

ishaan agarwal
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)
240 views4 pages

Essential Python Viva Questions Guide

The document lists important viva questions related to Python programming, covering topics such as language translation, data types, functions, file handling, and error types. It provides concise answers to each question, explaining concepts like mutable vs immutable types, slicing, comments, variable scope, and file operations. Additionally, it discusses the significance of stack operations and exceptions in Python.

Uploaded by

ishaan agarwal
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

Important Viva questions:

1. Which language translator is used by python?


o Interpreter
2. What are the built-in data types available in python?
o Numbers, Strings, Lists, Tuples, Dictionaries
3. How python interpreter interprets the code?
o Python interpreter interprets the code line by line.
4. Name a few mutable data types of python.
o Lists, Sets, and Dictionaries
5. Name a few immutable data types of python.
o Strings, Tuples, Numeric
6. What is slicing in python?
o Python slicing is a statement of python that extracts a list of
elements from the given sequence in the range of start and
stop values with step value intervals.
7. What are comments in python?
o Python comments are non-executable text written in the python
program to give a description for a statement or group of
statements.
8. What is the difference between / and //?
o / is used for division, // is used for floor division
o / returns float as answer whereas // returns integer as answer
o / gives you the number with decimal places whereas // gives
you only integer part
9. What is the difference between append() and extend() methods?
o append() is used to add an element to the list to the last.
o extend() is used to add multiple elements to the list.
10. What is a function?
o A function is a subprogram and a smaller unit of a python
program consists of a set of instructions and returns a value.
11. Does every python program must return a value?
o No, not every python program returns a value.
12. What are the parts of a function?
o A python function has the following parts:
 Function header – Starts with def keyword followed by
function name and parameters
 Function body – Block of statements/instructions that
define the action performed by the function, indentation
must be followed
 Function caller statement – writing function name
including parameter values
13. What are the needs of function in the python program?
o Easy program handling
o Reduce the size of the program
o Reduce the repeated statements
o Ambiguity can be reduced
o Make program more readable and understandable
14. What is indentation? Explain its importance in two lines.
o Indentation refers to white spaces added before each line of the
code.
o In python, it detects the block of code.
o It also makes the program more readable and presentable.
o It organizes the code of blocks in a good manner.
15. What are the comments? Explain the role of comments in
the python programs?
o Comments are non-executable parts of python programs.
o You can write a comment for the description or information
related to statements, basic details of programs etc.
o There are two types of comments:
 Single-Line: These comments written for explaining single
line comments, begins with #
 Multi-Line: These comments written for explaining multi-
line comments, begins and ends with ”’ triple quotes
16. Which three types of functions supported by python?
o Python supports the following three types of functions:
 Built-in Functions
 Functions defined in modules
 User-defined functions
17. What are parameters and arguments in python programs?
o Parameters are the values provided at the time of function
definition. For Ex. p,r and n.
o Arguments are the values passed while calling a function. For
Ex. princ_amt, r, n in main().
18. What do you mean by python variable scope?
o The python variable scope refers to the access location of the
variable defined in the program.
o A python program structure has different locations to declare
and access the variable.
o There are two scopes of variables in python:
 Local Scope
 Global Scope
19. What is the local and global scope variable?
o The variable which is declared inside a function and can be
accessible inside a function is known as local variable scope.
o The variable declared in top-level statements of the python
program is called a global variable scope, it is accessible
anywhere in the program.
20. Name few commonly used libraries in python.
o Standard library
o Numpy Library
o Matplotlib
o SciPy
21. What are the two ways to import modules?
o You can import modules in python using these two ways:
 import <modulename>
 from <module> import <object>
22. What is a file?
o A file is a stream of bytes stored on secondary storage devices
having an extension.
23. What are the different modes of opening a file?
o The different modes of opening a file are as follows:
 r,w,a,r+,w+,a+,rb,wb,ab,rb+,wb+,ab+
24. If no mode is specified in open() function, which mode will
be considered?
o r
25. What is the difference between “w” and “a” mode?
o “a” mode adds the content to the existing file whereas “w” mode
overwrites the contents into the file.
26. What is the difference between readline() and readlines()
function?
o readline() function reads the content of the text file and returns
the content into the string whereas readlines() function reads
the content of the text file and returns the content into the list.
27. Are CSV files and Text Files same?
o CSV files and Text Files are same in storage but csv file stores
the data separated by a delimiter.
28. What is pickling?
o Pickling refers to the process of converting python object
hierarchy into a byte stream to write into a binary file.
29. What is unpickling?
o It is the process of converting the byte stream back into an
object hierarchy.
30. Which module is required to handle binary files?
o pickle
31. Name the functions used to read and write data into binary
files.
o [Link](list_object, file_handle)
o [Link](file_object)
32. How to avoid reading file errors in binary file?
o By using exception handling with try and except blocks
33. What is the significance of tell() and seek() functions?
o tell() function returns the current file position in a file
o seek() function change the current file position
34. What are the operations can be performed on the stack?
o Push
o Pop
o Peep or Peek
35. Which principle is followed by stack?
o LIFO (Last in First Out)
36. Name any three applications of stack.
o Call history on mobile
o Browser history
o Undo and redo commands
o CD/DVD tracks
o Books on the tables
37. What is an exception in python?
o An error or unusual condition that occurs in the program that
causes abnormal termination of the program or crash of the
python program is called an exception.
38. Tell me the three basic types of errors that occur
in Python.
o Syntax Errors
o Logical Errors
o Run-Time Errors

Common questions

Powered by AI

Pickling converts Python object hierarchies into a byte stream, facilitating the storage of complex data structures while preserving their state and relationships. In contrast, traditional text file storage typically involves simple, readable data formats like CSV or TXT, which are easier to manage but unsuitable for storing complex or binary data without additional structure or parsing codes .

The Python interpreter executes a program line by line, which allows for immediate execution and checking of each line during the run-time of the program. This facilitates immediate feedback for errors as they appear, unlike compiled languages where the entire code must be error-free and compiled before execution. This means logical errors and syntax issues are often caught one line at a time, which can make debugging quicker but also means some errors are only found at runtime, not before execution .

Indentation in Python is used to define the structure by delineating blocks of code, such as the contents of loops and functions. Unlike other languages where brackets or specific keywords are used, Python's reliance on indentation enforces a consistent style, making scripts easier to read and ensuring that the logical groupings of statements are clearly communicated visually .

In Python, mutable data types such as lists, sets, and dictionaries allow for their content to be changed without changing their identity, meaning modifications can happen in-place which is efficient for memory management as it does not create copies. Immutable data types like strings, tuples, and numeric values cannot be changed once created, meaning any modification results in the creation of a new object, which can increase memory usage but ensures that the object state is preserved, enhancing data integrity .

Parameters refer to the variables defined by a function that are used to receive values, whereas arguments are the actual values passed to the function in its calling instance. Parameters act as placeholders within function definitions, allowing for generic logic definition, whereas arguments supply the actual data during execution, enabling specific instance processing .

Python slicing allows for extracting parts of sequences, such as lists or strings, using a specified start, stop, and step. This feature enables flexible, quick data manipulation as specific sections of data can be selected and modified without manually iterating over their parts. This can simplify code and make data manipulation more intuitive and compact .

Python provides various file modes for reading and writing files: 'r' for reading, 'w' for writing (overwrites existing files), 'a' for appending (adds to existing files), and their binary counterparts like 'rb' and 'wb'. Modes like 'r+' allow for both reading and writing. These different modes enable efficient manipulation of file content, tailored to whether new data should be inserted, existing data modified, or overwritten .

Variable scope in Python determines the accessibility and lifetime of variables, with local scope limiting access to within functions and global scope allowing access throughout the program. Local scope enables the encapsulation of functionality, reducing the risk of unintended interference with variables elsewhere in the code. Conversely, global scope is useful for variables that need access across different functions, contributing to variable sharing when necessary .

Python uses exceptions to manage errors, providing try, except, and finally blocks to handle them gracefully. This allows for capturing specific error types and enabling the program to continue execution or shut down gracefully, contributing to robust applications by enabling developers to anticipate and manage potential failure points within their code and ensure consistent application behavior .

Python supports built-in functions, functions defined in modules (e.g., from libraries), and user-defined functions. Built-in functions provide standard utility (e.g., len(), print()), module functions extend functionality through imports, and user-defined functions allow for tailored operations specific to the program's needs. These support modularity, reuse of code, and separating concerns, ultimately improving program organization and efficiency .

You might also like