1. What is lambda in Python?
Answer: lambda in Python is a single expression anonymous function often used as inline function. Is a way to define an unnamed function. It is used to is to define the key function when sorting a list
2. Why lambda forms in python does not have statements?
Answer: A lambda form in python does not have statements because it is used to make new function object and then return them at runtime. In simple words as their syntax is restricted to single expressions and they are used for creating function objects which are returned at runtime.
3. In Python what are iterators?
Answer: They are used to iterate a group of elements, containers like list in python. It is called repeatedly by a for loop; and an iterator is returned when the __iter__ method is called on an iterable. (such as zip, map, range and others).
4. In Python what is slicing?
Answer: In python, slicing is a string operation for extracting a part of the string, or some part of a list. It can also perform reverse indexing, i.e., in the backward direction, with the help of negative numbers. It is a mechanism to select a range of items from sequence types like list, tuple, strings etc.
5. What is docstring in Python?
Answer: Documenting python strings is known as docstring. It is a way of documenting Python modules, functions, classes. While adding comments as doc string will help viewers /users to get the gist of what exactly that particular function/class/piece of code is doing on high level.
6. How to display the contents of text file in reverse order?
Answer: To display the content of text file in reverse order follow the sequence below.
convert the given file into a list.
reverse the list by using reversed()
Eg: for line in reversed(list(open(“file-name”,”r”))):
7. What Is %S In Python?
Answer: Python has supported 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.
8. Is A String Immutable Or Mutable In Python?
Answer: Python strings are indeed immutable. Let’s take an example; i.e. we have a “str” variable holding a string value. We can’t mutate the container, i.e., the string, but can modify it.
9.What Is The Return Keyword Used For In Python?
Answer: The purpose of this function is to receive the inputs and return some output.The return is a Python statement which we can use in a function for sending a value back to its caller.
10. What Is The Return Value Of The Trunc() Function?
Answer: 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.