0% found this document useful (0 votes)
2 views

python-viva

Uploaded by

mishraji9333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python-viva

Uploaded by

mishraji9333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Python Viva Questions

What is Python?
• Python is a widely-used general-purpose, high-level,interpreted
programming language. It was created by Guido van Rossum in 1980.
What are the benefits of using Python language
The following are the benefits of using Python language:
• Object-Oriented Language
• High-Level Language
• Dynamically Typed language
• Extensive support for Machine Learning Libraries
• Presence of third-party modules
• Open source and community development
• Portable and Interactive
• Portable across Operating systems
Is Python a compiled language or an
interpreted language?
Python is primarily an interpreted language, meaning it executes code
line by line at runtime using an interpreter. It does have a compilation
step where the source code is converted to bytecode, which is then
executed by the Python Virtual Machine (PVM). This allows for
flexibility and ease of debugging, but it may result in slower execution
compared to fully compiled languages.
What does the ‘#’ symbol do in Python?
‘#’ is used to comment on everything that comes after on the line.

What is the difference between a Mutable datatype and an


Immutable data type?
Mutable data types can be edited i.e., they can change at runtime. Eg –
List, Dictionary, etc.
Immutable data types can not be edited i.e., they can not change at
runtime. Eg – String, Tuple, etc
What is the difference between a Set and
Dictionary?
The set is unordered collection of unique items that is iterable and
mutable. A dictionary in Python is an ordered collection of data values,
used to store data values like a map.
What is a lambda function?
A lambda function in Python is a small, anonymous function defined
using the lambda keyword It can take any number of arguments but
can only have a single expression. Lambda functions are often used for
short, throwaway functions that are not needed elsewhere in the code.
add = lambda x, y: x + y
result = add(3, 5) # result is 8
What is a pass in Python?
Pass means performing no operation or in other words, it is a
placeholder in the compound statement, where there should be a
blank left and nothing has to be written there.

What is the difference between / and // in Python?


/ represents precise division (result is a floating point number) whereas
// represents floor division (result is an integer). For Example:

5//2 = 2
5/2 = 2.5
How is Exceptional handling done in Python?
• There are 3 main keywords i.e. try, except, and finally which are used
to catch exceptions and handle the recovering mechanism
accordingly. Try is the block of a code that is monitored for errors.
Except block gets executed when an error occurs.
• The beauty of the final block is to execute the code after trying for an
error. This block gets executed irrespective of whether an error
occurred or not. Finally, block is used to do the required cleanup
activities of objects/variables
Difference between for loop and while loop in
Python
The “for” Loop is generally used to iterate through the elements of
various collection types such as List, Tuple, Set, and Dictionary.
Developers use a “for” loop where they have both the conditions start
and the end. Whereas, the “while” loop is the actual looping feature
that is used in any other programming language. Programmers use a
Python while loop where they just have the end conditions.
What are *args and **kwargs?
To pass a variable number of arguments to a function in Python, use
the special syntax *args and **kwargs in the function specification.
Both are to send a variable-length argument list. The syntax *args is
used to pass a non-keyworded, variable-length argument list.

Is Indentation Required in Python?


Yes, indentation is required in Python. A Python interpreter can be
informed that a group of statements belongs to a specific block of code
by using Python indentation. Indentations make the code easy to read
for developers in all programming languages but in Python, it is very
important to indent the code in a specific order.
What is Scope in Python?
The location where we can find a variable and also access it if required
is called the scope of a variable.
• Python Local variable: Local variables are those that are initialized
within a function and are unique to that function. It cannot be
accessed outside of the function.
• Python Global variables: Global variables are the ones that are
defined and declared outside any function and are not specified to
any function.
What is a break, continue, and pass in
Python?
• The break statement is used to terminate the loop or statement in
which it is present. After that, the control will pass to the statements
that are present after the break statement, if available.
• Continue is also a loop control statement just like the break
statement. continue statement is opposite to that of the break
statement, instead of terminating the loop, it forces to execute the
next iteration of the loop.
• Pass means performing no operation or in other words, it is a
placeholder in the compound statement, where there should be a
blank left and nothing has to be written there.
What are Built-in data types in Python?
The following are the standard or built-in data types in Python:
• Numeric: The numeric data type in Python represents the data that has a numeric value. A
numeric value can be an integer, a floating number, a Boolean, or even a complex number.
• Sequence Type: The sequence Data Type in Python is the ordered collection of similar or different
data types. There are several sequence types in Python:
• Python String
• Python List
• Python Tuple
• Python range
• Mapping Types: In Python, hashable data can be mapped to random objects using a mapping
object. There is currently only one common mapping type, the dictionary, and mapping objects
are mutable.
• Python Dictionary
• Set Types: In Python, a Set is an unordered collection of data types that is iterable, mutable, and
has no duplicate elements. The order of elements in a set is undefined though it may consist of
various elements.
What are Built-in data types in Python?
Let’s analyze the differences between List and Tuple:
• List
• Lists are Mutable datatype.
• Lists consume more memory
• The list is better for performing operations, such as insertion and deletion.
• The implication of iterations is Time-consuming
• Tuple
• Tuples are Immutable datatype.
• Tuple consumes less memory as compared to the list
• A Tuple data type is appropriate for accessing the elements
• The implication of iterations is comparatively Faster
Does Python supports multiple Inheritance?
Python does support multiple inheritances, unlike Java. Multiple inheritances mean that a class can be derived
from more than one parent class.

What is Polymorphism in Python?


Polymorphism means the ability to take multiple forms. Polymorphism allows different classes to be treated as
if they are instances of the same class through a common interface. This means that a method in a parent class
can be overridden by a method with the same name in a child class, but the child class can provide its own
specific implementation. This allows the same method to operate differently depending on the object that
invokes it. Polymorphism is about overriding, not overloading; it enables methods to operate on objects of
different classes, which can have their own attributes and methods, providing flexibility and reusability in the
code.
Define encapsulation in Python?
Encapsulation means binding the code and the data together. A Python
class is an example of encapsulation.

How do you do data abstraction in Python?


Data Abstraction is providing only the required details and hides the
implementation from the world. It can be achieved in Python by using
interfaces and abstract classes.
What is slicing in Python?
Python Slicing is a string operation for extracting a part of the string, or
some part of a list. With this operator, one can specify where to start
the slicing, where to end, and specify the step. List slicing returns a new
list from the existing list.

What is a namespace in Python


A namespace is a naming system used to make sure that names are
unique to avoid naming conflicts

You might also like