Posts Tagged with 'Python'

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 …

Last updated 2 years, 2 months ago | 907 views

Tags:- Python

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 …

Last updated 2 years, 2 months ago | 882 views

Tags:- 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 …

Last updated 2 years, 2 months ago | 880 views

Tags:- Python

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 …

Last updated 2 years, 4 months ago | 903 views

Tags:- 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 …

Last updated 2 years, 4 months ago | 867 views

Tags:- Python

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 …

Last updated 2 years, 4 months ago | 890 views

Tags:- Python

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. …

Last updated 2 years, 4 months ago | 885 views

Tags:- Python

If bool(a) returns False, then x is assigned the value of b.

Last updated 2 years, 4 months ago | 998 views

Tags:- 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.  

Last updated 2 years, 4 months ago | 954 views

Tags:- 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 …

Last updated 2 years, 5 months ago | 912 views

Tags:- 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 …

Last updated 2 years, 5 months ago | 885 views

Tags:- Python

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 …

Last updated 2 years, 5 months ago | 913 views

Tags:- Python

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 …

Last updated 2 years, 5 months ago | 873 views

Tags:- 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, …

Last updated 2 years, 5 months ago | 901 views

Tags:- Python

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 …

Last updated 2 years, 5 months ago | 928 views

Tags:- Python