Posts Tagged with 'Python'
Program to check all numbers are unique in a sequence.
You can do this by converting the list to a set using the set() method and comparing the length of this set with the length of the original list. If found equal, return True else …
What are decorators?
Python | What are decorators A decorator in Python is a function that modifies the behavior of an existing function or class without any modification to the original source code. A decorator takes another function as its argument and returns yet …
What are unit tests in Python?
Python | What are unit tests Unit test is a testing technique to check a single component of code and ensures that it performs as expected. Unit tests are an important part of regression testing to ensure that …
“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 and pass them as arguments to other functions. You can even return them from another function. You …
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 …