Blog available for sell
This blog is available for sale. Please 'contact us' if interested.
Advertise with us

Python Interview Questions
31. What’s The Process To Get The Home Directory Using ‘~’ In Python?
A:
import os
print (os.path.expanduser('~'))
>>> import os
>>> print (os.path.expanduser('~'))
/home/rana
32. How Does Python Handle Memory Management?
A: Python uses private heaps to maintain its memory. So the heap holds all the Python objects and the data structures. This area is only accessible to the Python interpreter; programmers can’t use it.

And it’s the Python memory manager that handles the Private heap. It does the required allocation of the memory for Python objects.

Python employs a built-in garbage collector, which salvages all the unused memory and offloads it to the heap space.
33. What Are The Principal Differences Between The Lambda And Def?
A: Def can hold multiple expressions while lambda is a uni-expression function.
Def generates a function and designates a name to call it later. Lambda forms a function object and returns it.
Def can have a return statement. Lambda can’t have return statements.
Lambda supports to get used inside a list and dictionary.
34. What Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?
list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
A: The result of the above lines of code is []. There won’t be any error like an IndexError.

Trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError. Retrieving only a slice at the starting index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.
35. What Are The Optional Statements Possible Inside A Try-Except Block In Python?
A: The “else” clause:
It is useful if you want to run a piece of code when the try block doesn’t create an exception.

The “finally” clause:
It is useful when you want to execute some steps which run, irrespective of whether there occurs an exception or not.

36. What Is %S In Python?
A: Python has support for formatting any value into a string. It may contain quite complex expressions.

One of the common usages is to push values into a string with the %s format specifier. The formatting operation in Python has the comparable syntax as the C function printf() has.
37. Is A String Immutable Or Mutable In Python?
A: Python strings are indeed immutable.

Let’s take an example. We have an “str” variable holding a string value. We can’t mutate the container, i.e., the string, but can modify what it contains that means the value of the variable.
38. What Is Docstring In Python?
A: A docstring is a unique text that happens to be the first statement in the following Python constructs:
Module, Function, Class, or Method definition.

A docstring gets added to the __doc__ attribute of the string object.
39. What Is The Return Value Of The Trunc() Function?
A: The Python trunc() function performs a mathematical operation to remove the decimal values from a particular expression and provides an integer value as its output.
40. What Does The Continue Do In Python?
A: The continue is a jump statement in Python which moves the control to execute the next iteration in a loop leaving all the remaining instructions in the block unexecuted.





DigitalOcean Referral Badge

© 2024-2025 Python Circle   Contact   Sponsor   Archive   Sitemap