Python Expert

1 / 55

Why do floating-point calculations seem inaccurate in Python?

Select the correct answer

1

Floating-point calculations seem inaccurate due to Python's internal bugs.

2

Floating-point calculations seem inaccurate due to binary representation limitations.

3

Floating-point calculations seem inaccurate due to incorrect math operations.

4

Floating-point calculations seem inaccurate due to outdated Python versions.

When Python program exits, why isn’t all the memory de-allocated?

Select the correct answer

1

Not all memory is de-allocated because of cyclic references and the garbage collector's limitations.

2

Memory is de-allocated only in Python 3.

3

All memory is de-allocated when a Python program exits.

4

Memory is not de-allocated due to Python's memory leak.

What is the difference between .py and .pyc files?

Select the correct answer

1

.py files contain the source code, while .pyc files contain the compiled bytecode.

2

.py files are compiled files, while .pyc files are source files.

3

.py files are used for documentation, while .pyc files are used for execution.

4

.py files are for testing, while .pyc files are for production.

How Python is interpreted?

Select the correct answer

1

Python is interpreted, meaning code is executed line by line.

2

Python is compiled, meaning code is converted to machine code.

3

Python uses both compilation and interpretation simultaneously.

4

Python is a hybrid language.

What is the process of compilation and linking in python?

Select the correct answer

1

Python code is compiled into bytecode, which is then interpreted.

2

Python code is compiled into machine code, which is then executed directly.

3

Python code is not compiled, it is interpreted line by line.

4

Python code is linked directly to the OS.

How is multithreading achieved in Python?

Select the correct answer

1

Multithreading in Python is achieved using the multiprocessing module.

2

Multithreading in Python is not supported.

3

Multithreading in Python is achieved using the threading module.

4

Multithreading in Python is achieved using the concurrent module.

What are function annotations in Python?

Select the correct answer

1

Function annotations in Python are used for exception handling.

2

Function annotations in Python are a way of associating metadata with function arguments and return values.

3

Function annotations in Python are used to create abstract methods.

4

Function annotations in Python are a form of comments.

What is monkey patching in Python?

Select the correct answer

1

Monkey patching is a method of testing code.

2

Monkey patching is a way to document code.

3

Monkey patching is creating multiple versions of a class.

4

Monkey patching is dynamically modifying a class or module at runtime.

What are generators in Python?

Select the correct answer

1

Generators in Python are functions that run indefinitely.

2

Generators in Python are a way to create dictionaries using yield statements.

3

Generators in Python are used to create threads.

4

Generators in Python are a way to create iterators using yield statements.

What are Eggs and Wheels in Python?

Select the correct answer

1

Eggs and Wheels are Python IDEs.

2

Eggs and Wheels are packaging formats used for distributing Python projects.

3

Eggs and Wheels are tools for Python testing.

4

Eggs and Wheels are Python debugging tools.

Describe memory management in Python.

Select the correct answer

1

Memory management in Python is handled by the Python memory manager and includes garbage collection.

2

Memory management in Python is handled manually by the programmer.

3

Memory management in Python is handled by the operating system.

4

Memory management in Python is only for built-in types.

Does Python support multiple inheritance?

Select the correct answer

1

Yes, but only in Python 3.

2

No, Python does not support multiple inheritance.

3

Yes, Python supports multiple inheritance.

4

Yes, but only with metaclasses.

What is inheritance in Python?

Select the correct answer

1

Inheritance in Python allows a class to inherit attributes and methods from another class.

2

Inheritance in Python is used to encapsulate methods.

3

Inheritance in Python prevents method overriding.

4

Inheritance in Python allows creating private methods.

What is polymorphism in Python?

Select the correct answer

1

Polymorphism in Python allows objects to have multiple forms.

2

Polymorphism in Python is achieved using the init method.

3

Polymorphism in Python refers to object inheritance.

4

Polymorphism in Python allows methods to do different things based on the object it is acting upon.

What is encapsulation in Python?

Select the correct answer

1

Encapsulation in Python is achieved by using decorators.

2

Encapsulation in Python is achieved by using only methods.

3

Encapsulation in Python is achieved by using public members only.

4

Encapsulation in Python is achieved by using private and protected members.

How is data abstraction achieved in Python?

Select the correct answer

1

Data abstraction in Python is achieved using the init method.

2

Data abstraction in Python is achieved using global variables.

3

Data abstraction in Python is achieved using the pass statement.

4

Data abstraction in Python is achieved using abstract classes and interfaces.

What are access specifiers in Python?

Select the correct answer

1

Python uses self for access specifiers.

2

Python uses private, public, and protected keywords.

3

Python does not have access specifiers like private, public, and protected.

4

Python uses decorators for access specifiers.

What is self in Python?

Select the correct answer

1

self in Python refers to the instance of the class.

2

self in Python refers to the class itself.

3

self in Python is a global variable.

4

self in Python is a keyword to access methods.

What is a zip function?

Select the correct answer

1

The zip function pairs elements from multiple iterables.

2

The zip function sorts elements from multiple iterables.

3

The zip function concatenates elements from multiple iterables.

4

The zip function filters elements from multiple iterables.

What is the difference between return and yield keywords?

Select the correct answer

1

The return keyword produces a generator, while yield sends a result back to the caller.

2

The return keyword is used in loops, while yield is used in functions.

3

The return keyword pauses a function, while yield stops a function.

4

The return keyword sends a result back to the caller, while yield produces a generator.

What’s the difference between a Set and a Frozenset?

Select the correct answer

1

A frozenset is immutable, while a set is mutable.

2

A frozenset is mutable, while a set is immutable.

3

A frozenset can be indexed, while a set cannot.

4

A frozenset is a subclass of set.

What is the difference between a Set and Dictionary?

Select the correct answer

1

A set allows duplicate items, while a dictionary does not.

2

A set is a collection of key-value pairs, while a dictionary is an unordered collection of unique items.

3

A set is an unordered collection of unique items, while a dictionary is a collection of key-value pairs.

4

A set is immutable, while a dictionary is mutable.

What are some of the differences between Lists and Tuples?

Select the correct answer

1

Lists can be nested, while tuples cannot.

2

Lists are for numeric data, while tuples are for text data.

3

Lists are immutable, while tuples are mutable.

4

Lists are mutable, while tuples are immutable.

What is a context manager in Python?

Select the correct answer

1

A context manager in Python is used for data storage.

2

A context manager in Python is used for string manipulation.

3

A context manager in Python handles exceptions.

4

A context manager in Python allows for resource management.

What is pickling and unpickling?

Select the correct answer

1

Pickling is the process of copying a Python object.

2

Pickling is the process of converting a Python object into a byte stream.

3

Pickling is the process of converting a Python object into a string.

4

Pickling is the process of encrypting a Python object.

Explain the logical operations in Python.

Select the correct answer

1

Logical operations in Python include equals, greater than, and less than.

2

Logical operations in Python include if, elif, and else.

3

Logical operations in Python include add, subtract, and multiply.

4

Logical operations in Python include and, or, and not.

What is PIP?

Select the correct answer

1

PIP is a package management system used to install and manage Python packages.

2

PIP is a Python interpreter.

3

PIP is an IDE for Python.

4

PIP is a debugging tool in Python.

What is main function in Python?

Select the correct answer

1

The main function in Python is used to import modules.

2

The main function in Python is executed when the script is run directly.

3

The main function in Python is used to declare global variables.

4

The main function in Python is called before every function.

What is the Python with statement used for?

Select the correct answer

1

The with statement in Python is used for resource management.

2

The with statement in Python is used for conditionals.

3

The with statement in Python is used for function definitions.

4

The with statement in Python is used for loops.

What are Iterators in Python?

Select the correct answer

1

Iterators in Python are objects that hold multiple items at once.

2

Iterators in Python are objects that implement the iterator protocol.

3

Iterators in Python are built-in functions for looping.

4

Iterators in Python are only used for dictionaries.

How can you insert an element into a specific position in a list?

Select the correct answer

1

You can insert an element into a specific position in a list using the append() method.

2

You can insert an element into a specific position in a list using the extend() method.

3

You can insert an element into a specific position in a list using the update() method.

4

You can insert an element into a specific position in a list using the insert() method.

Does removing the first item from a Python list take the same amount of time as removing the last item?

Select the correct answer

1

Removing the first item from a list is always faster than removing the last item.

2

Removing the first item from a list takes the same time as removing the last item.

3

Removing the first item from a list takes longer than removing the last item.

4

Removing the first item from a list is not allowed in Python.

What is enumerate() in Python?

Select the correct answer

1

enumerate() in Python adds a counter to an iterable and returns it.

2

enumerate() in Python concatenates iterables and returns it.

3

enumerate() in Python filters an iterable and returns it.

4

enumerate() in Python sorts an iterable and returns it.

What is a closure in Python?

Select the correct answer

1

A closure in Python is a function without any arguments.

2

A closure in Python is a nested function which has access to variables of the outer function.

3

A closure in Python is a function that only exists at runtime.

4

A closure in Python is a function that is called immediately after it is defined.

What is the difference between a module and a package in python?

Select the correct answer

1

A module is used for object-oriented programming, while a package is for functional programming.

2

A module is a built-in Python function, while a package is a user-defined function.

3

A module is a collection of packages, while a package is a single file containing Python code.

4

A module is a single file containing Python code, while a package is a collection of modules.

What is a namespace in Python?

Select the correct answer

1

A namespace in Python is a container that holds a set of identifiers and their corresponding objects.

2

A namespace in Python is a function scope.

3

A namespace in Python is a variable type.

4

A namespace in Python is a special type of module.

What's the difference between sort() and sorted() in Python?

Select the correct answer

1

Both sort() and sorted() modify the list in-place.

2

Both sort() and sorted() return a new list.

3

sort() modifies the list in-place, while sorted() returns a new list.

4

sort() returns a new list, while sorted() modifies the list in-place.

What is PYTHONPATH?

Select the correct answer

1

PYTHONPATH is a file path for the Python interpreter.

2

PYTHONPATH is an environment variable which you can set to add additional directories where Python will look for modules and packages.

3

PYTHONPATH is a type of Python variable.

4

PYTHONPATH is the default directory for Python scripts.

What is a lambda function in Python?

Select the correct answer

1

A lambda function is used to declare variables.

2

A lambda function is a named function in Python.

3

A lambda function is used to create classes.

4

A lambda function is a small anonymous function in Python.

What is the Global Interpreter Lock (GIL) in Python?

Select the correct answer

1

The Global Interpreter Lock (GIL) is a performance enhancement.

2

The Global Interpreter Lock (GIL) is a mutex that protects access to Python objects.

3

The Global Interpreter Lock (GIL) is a security feature in Python.

4

The Global Interpreter Lock (GIL) is used for thread optimization.

What is the difference between Arrays and lists in Python?

Select the correct answer

1

Arrays are a part of standard Python library, while lists are not.

2

Arrays are dynamic-size, while lists are fixed-size.

3

Arrays can contain mixed types, while lists cannot.

4

Arrays are fixed-size, while lists are dynamic-size.

Explain the difference between deep copy and shallow copy in Python.

Select the correct answer

1

A deep copy does not copy objects, while a shallow copy does.

2

A deep copy copies all objects recursively, while a shallow copy does not.

3

A deep copy copies only immutable objects, while a shallow copy does not.

4

A deep copy only copies primitive types, while a shallow copy does not.

Explain list comprehensions in Python.

Select the correct answer

1

List comprehensions are only used for filtering lists.

2

List comprehensions are used to define list classes.

3

List comprehensions provide a concise way to create lists.

4

List comprehensions are used to generate tuples.

What is the purpose of the __init__ method in a Python class?

Select the correct answer

1

The __init__ method initializes an instance of a class.

2

The __init__ method is used to create a new class.

3

The __init__ method is a destructor method.

4

The __init__ method is only used for inheritance.

Explain the use of the map() function in Python.

Select the correct answer

1

The map() function applies a function to all items in an iterable.

2

The map() function filters elements from a list.

3

The map() function converts a list to a dictionary.

4

The map() function sorts the elements in an iterable.

What is scope in Python?

Select the correct answer

1

Scope in Python refers to the visibility of variables.

2

Scope in Python refers to the size of variables.

3

Scope in Python is used to determine data types.

4

Scope in Python is a method for optimizing memory.

What are negative indexes in Python?

Select the correct answer

1

Negative indexes in Python start the count from zero.

2

Negative indexes in Python are used for error handling.

3

Negative indexes in Python are only for string manipulation.

4

Negative indexes in Python allow counting from the end of a list.

What is a docstring in Python, and why is it useful?

Select the correct answer

1

A docstring is a string literal used for documentation in Python.

2

A docstring is a variable name in Python.

3

A docstring is a type of exception in Python.

4

A docstring is a comment used to document code in Python.

Explain the pass statement in Python.

Select the correct answer

1

The pass statement pauses the execution of code.

2

The pass statement raises an exception.

3

The pass statement exits the current loop.

4

The pass statement is a no-op placeholder in Python.

How do you handle exceptions in Python?

Select the correct answer

1

Exceptions in Python are handled using try and except blocks.

2

Exceptions in Python are handled using error and catch blocks.

3

Exceptions in Python are handled using try and catch blocks.

4

Exceptions in Python are handled using validate and except blocks.

Is Python pass by reference or pass by value?

Select the correct answer

1

Python is pass by reference.

2

Python is pass by value.

3

Python uses a mix of pass by reference and pass by value.

4

Python is pass by object reference.

Explain mutable and immutable data types in Python?

Select the correct answer

1

Mutable types can be changed after creation, while immutable types cannot.

2

Only strings in Python are immutable.

3

Mutable types cannot be changed after creation, while immutable types can.

4

Both mutable and immutable types cannot be changed after creation.

What is PEP 8, and why is it important?

Select the correct answer

1

PEP 8 is a security standard in Python.

2

PEP 8 is a Python error prevention tool.

3

PEP 8 is a performance enhancement proposal.

4

PEP 8 is the style guide for writing Python code.

Is Python statically or dynamically typed?

Select the correct answer

1

Python is dynamically typed.

2

Python is statically typed.

3

Python uses type inference.

4

Python is weakly typed.

Is Python a compiled language or an interpreted language?

Select the correct answer

1

Python is an interpreted language.

2

Python is a low-level programming language.

3

Python is a compiled language.

4

Python is a scripting language only.