Posts Tagged with 'Python'
“in Python, Functions Are First-class Objects.” What Do You Infer from this?
It means that a function can be treated just like an object. You can assign them to variables, or pass them as arguments to other functions. You can even return them from other functions.
What is slicing in Python?
Python | Slicing As the name suggests, ‘slicing’ is taking parts of sequences like lists, tuples, and strings. Syntax for slicing is [start : stop : step] The start is the starting index from where to slice a …
What is a dynamically typed language?
Python is an interpreted language, that executes each statement line by line and thus type-checking is done on the fly, during execution. Hence, Python is a Dynamically Typed Language. Typing refers to type-checking in programming …
Explain the difference between @staticmethod and @classmethod?
Python | Difference between @staticmethod and @classmethod A staticmethod is a method that knows nothing about the class or the instance it was called on. It just gets the arguments that were passed, no implicit first argument. …
What does an x = y or z assignment do in Python?
If bool(a) returns False, then x is assigned the value of b.
What is docstring in Python?
Python | Docstring A documentation string or docstring is a multiline string used to document a specific code segment. The docstring should describe what the function or method does.
What is yield in Python?
yield is a keyword beares the ability to turn any function into a generator. Much like the standard return keyword, but returns a generator object. It is also true that one function may observe multiple …
Difference between module and package?. addon how do you create package in python?
Python | Module and Package Module: The module is a simple Python file that contains collections of functions and global variables and with having a .py extension file. It is an executable file and to organize all …
Explain context manager. Can you write your own context manager example?
Python | context manager Context managers allow you to allocate and release resources precisely when you want to. The most widely used example of context managers is the with() statement. with open('some_file', 'w') as opened_file: opened_file.write('Hola!') The …
What is a namedtuple?
Python | namedtuple A namedtuple will let us access a tuple’s elements using a name/label. We use the function namedtuple() for this, and import it from collections. >>> from collections import namedtuple #format >>> result=namedtuple('result','Physics Chemistry …
How is memory managed in Python?
Python | Memory manage Python has a private heap space to hold all objects and data structures. Being programmers, we cannot access it; it is the interpreter that manages it. But with the core API, …
What are accessors, mutators, and @property?
Python | accessors, mutators, and @property What we call getters and setters in languages like Java, we term accessors and mutators in Python. In Java, if we have a user-defined class with the property ‘x’, we …
Does Python support interfaces like Java does?
No. However, Abstract Base Classes (ABCs) are a feature from the abc module that let us declare what methods subclasses should implement. Python supports this module since version 2.7.
What is the MRO in Python?
MRO stands for Method Resolution Order. Talking of multiple inheritances, whenever we search for an attribute in a class, Python first searches in the current class. If found, its search is satiated. If not, it …
Can you explain the filter(), map(), and reduce() functions?
Python | filter(), map(), and reduce() Functions filter() function accepts two arguments, a function and an iterable, where each element of the iterable is filtered through the function to test if the item is accepted or …