31. Python: isinstance, Use of format, Timeit, round, Slice and abs

2 months ago
130

1. isinstance() function returns True if the specified object is of the specified type, otherwise False. If the type parameter is a tuple, this function will return True if the object is one of the types in the tuple.
2. format() method formats the specified value(s) and insert them inside the string's placeholder. The placeholder is defined using curly brackets: {}. Read more about the placeholders in the Placeholder section below. format() method returns the formatted string.
3. timeit() method measure execution time of small code snippets. This module provides a simple way to time small bits of Python code.
4. round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals. The default number of decimals is 0, meaning that the function will return the nearest integer.
5. slice() function returns a slice object. A slice object is used to specify how to slice a sequence. You can specify where to start the slicing, and where to end. You can also specify the step, which allows you to e.g. slice only every other item.
6. abs() function returns the absolute value of the specified number.

Loading 1 comment...