Python interview questions from topFAANG+ companies are based on theoretical and practical knowledge. If you’re preparing for a technical interview and have decided to use Python as your programming language, these Python interview questions and answers will help you understand what to expect. If y...
A new list can be generated based on an existing one by applying conditions or transformations within a single line. Example: Python Copy Code Run Code 1 2 3 4 # squaring even numbers list_comprehension = [i**2 for i in range(5) if i%2==0] print(list_comprehension) 7. What ...
You can use split() function to split a string based on a delimiter to a list of strings. You can use join() function to join a list of strings based on a delimiter to give a single string. string = "This is a string." string_list = string.split(' ') #delimiter is ‘space’...
Is Python platform independent? Yes, Python is platform independent. Code written in Python can be executed on various operating systems without modification, thanks to its interpreters available for different platforms. Continue Reading...Related Topics Python Interview Questions (Part 2) Python Interv...
@my_decoratordefmy_func(stuff): do_things equivalent todefmy_func(stuff): do_things my_func = my_decorator(my_func) Q: Python's garbage collection mechanism A: Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the as...
19.How are global and local variables defined in Python? In general, variables defined outside of functions are global. Variables defined inside a function can also be made global by using the command global x, for example, to create a global variable called x. ...
A function in Python is a block of reusable code that performs a specific task. In Python, functions are defined using the “def” keyword, followed by the function name, and a set of parentheses that may include parameters. The function body is indented and contains the code that performs...
print functionThis is the most well-known change. In this, the print keyword in Python 2.x is replaced by the print() function in Python 3.x. However, parentheses work in Python 2 if space is added after the print keyword because the interpreter evaluates it as an expression....
5. What is Monkey Patching? How to use it in Python? Monkey patching is the practice of modifying the behavior of code at run-time. This is possible to do in Python by reassigning function addresses. class A: def greeting(): print ("Greetings!") ...
Simply, a pure function is a process that takes input values and returns output values based only on the input values. Pure functions have no "side effects," meaning that they have no influence on other variables in the program, don’t perform writing to files, and don’t alter ...