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

Python Viva Voice Questions

The document provides an overview of Python programming concepts, including control statements like break, continue, and pass, as well as data types such as numeric, sequence, mapping, and set types. It explains the differences between lists, tuples, and sets, and discusses the importance of scope, indentation, and the use of modules and packages for code organization. Additionally, it highlights the definitions and purposes of functions and the distinction between mutable and immutable objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Viva Voice Questions

The document provides an overview of Python programming concepts, including control statements like break, continue, and pass, as well as data types such as numeric, sequence, mapping, and set types. It explains the differences between lists, tuples, and sets, and discusses the importance of scope, indentation, and the use of modules and packages for code organization. Additionally, it highlights the definitions and purposes of functions and the distinction between mutable and immutable objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Viva Voice sample Questions:

Break The break statement terminates the loop immediately


and the control flows to the statement after the body of
the loop.
Continu The continue statement terminates the current iteration
e of the statement, skips the rest of the code in the
current iteration and the control flows to the next
iteration of the loop.
Pass As explained above, the pass keyword in Python is
generally used to fill up empty blocks and is similar to
an empty statement represented by a semi-colon in
languages such as Java, C++, Javascript, etc.

3. Modules, in general, are simply Python files with a .py


extension and can have a set of functions, classes, or variables
defined and implemented. They can be imported and initialized
once using the import statement. If partial functionality is
needed, import the requisite classes or functions using from foo
import bar.

Packages allow for hierarchial structuring of the module .


packages help avoid clashes between module names.

3.None data - Represents the NULL values in


Type Python.

Numeric Data Types :

Stores integer literals including hex, octal and binary


int
numbers as integers
Stores literals containing decimal values and/or
float
exponent signs as floating-point numbers
Stores complex numbers in the form (A + Bj) and has
complex
attributes: real and imag
bool Stores boolean value (True or False).

Sequence Data Types:

list Mutable sequence used to store collection of items.


tuple Immutable sequence used to store collection of items.
Represents an immutable sequence of numbers generated
range
during execution.
str

 Mapping Data Types:

-Stores comma-separated list of key:


dict
value pairs

Set Data Types:

-Mutable unordered collection of distinct hashable


set
objects.

What are lists and tuples? What is the key difference


between the two?

Lists and Tuples are both sequence data types that can store
a collection of objects in Python. The objects stored in both
sequences can have different data types. Lists are represented
with square brackets ['sara', 6, 0.19], while tuples are
represented with parantheses ('ansh', 5, 0.97).
But what is the real difference between the two? The key
difference between the two is that while lists are
mutable, tuples on the other hand are immutable objects. This
means that lists can be modified, appended or sliced on the go
but tuples remain constant and cannot be modified in any
manner.
 A local scope refers to the local objects available in the current
function.
 A global scope refers to the objects available throughout the
code execution since their inception.

What is Python? What are the benefits of using Python

Python is a high-level, interpreted, general-purpose programming


language. Being a general-purpose language, it can be used to
build almost any type of application with the right tools/libraries.
Additionally, python supports objects, modules, threads,
exception-handling, and automatic memory management which
help in modelling real-world problems and building applications to
solve these problems.

What is slicing in Python?

 As the name suggests, ‘slicing’ is taking parts of.


 Syntax for slicing is [start : stop : step]
 start is the starting index from where to slice a list or tuple
 stop is the ending index or where to sop.
 step is the number of steps to jump.
 Default value for start is 0, stop is number of items, step is 1.
 Slicing can be done on strings, arrays, lists, and tuples.

Can you list Python's primary built-in data types, in categories?

 Text Type: str


 Numeric Types: int, float, complex
 Sequence Types: list, tuple, range
 Mapping Type: dict
 Set Types: set, frozenset
 Boolean Type: bool

What is indentation in Python, and why is it important?

 Indentation refers to the spaces at the beginning of a code


line. Where in other programming languages the indentation
in code is for readability only, the indentation in Python is
very important.
 Python uses indentation to indicate a block of code.
 Python will give you an error if you skip the indentation.

What is the difference between lists, tuples and sets?

 Lists, tuples and sets are all used to store multiple items in a
single variable.
 A list is a collection of data which is ordered and changeable
(elements can be added, removed and changed).
 A tuple is a collection of data which is ordered and
unchangeable (elements cannot be added, removed or
changed).
 A set is a collection of data which is unordered,
unchangeable, and unindexed.

What is the difference between global and local scope?

 A variable created inside a function belongs to the local


scope of that function, and can only be used inside that
function.
 A variable created in the main body of the Python code is a
global variable and belongs to the global scope. Global
variables are available from within any scope, global and
local.

What are the basic data types in Python? Python has


several basic data types:

 Numbers: Integers (whole numbers), floats


(decimals), booleans (True/False).
 Strings: Sequences of characters enclosed in quotes
(e.g., “Hello”).
 Lists: Ordered collections of elements enclosed in square
brackets (e.g., [1, 2, “apple”]).
 Tuples: Similar to lists but immutable (cannot be changed)
and enclosed in parentheses (e.g., (1, 2, “apple”)).
 Sets: Unordered collections of unique elements enclosed in
curly braces (e.g., {1, 2, 3}).
 Dictionaries: Key-value pairs enclosed in curly braces
(e.g., {“name”: “John”, “age”: 30}).

What are functions and how do you define them?

 Reusable blocks of code that take arguments and perform


specific tasks.
 Defined with def:

What is the purpose of modules and packages in Python?

 Modules group related functions and variables.


 Packages group modules into hierarchies.
 Used for code organization and import for reuse.

Explain the difference between mutable and immutable


objects.

 Mutable: Can be changed (e.g., lists, dictionaries).


 Immutable: Cannot be changed (e.g., strings, tuples)

You might also like