The Counter subclass in Python

Python Counter

A counter is a subclass of the dict (From collections library), is used to count the hashtable objects. elements of the iterable like lists can be counted by using Counter.

Getting substring in Python

Python substring

While there is no formal method like “substring” or “substr” etc. to get substrings in Python, the techniques are called slicing and extended slicing.

The break statement in Python

Python break

The Python break statement is used to terminate the for or while loops. Normally, the loop ends as the testing condition fails. However, in certain scenarios, you may require ending the loop earlier

Types of Errors in Python?

Python try except

The errors occur as a program is executed or running is called exception. These errors must be handled or a program will crash and may leave a confusion or bad impression on the user’s part.

Is Python foreach loop available?

Python foreach

The purpose of foreach loop is to iterate through arrays or collections easily. Then why Python does not support it? Well, there is another handy way of doing this job quite easily. You can say doing foreach in Pythonic way.

What is Python ord() function?

Python ord

The Python ord() function is used to return an integer of the given single Unicode character. Inversely, the Python chr() function takes a Unicode code point (integer) and returns a string.

Writing Python comments

Python multiline comment

For single line comments, you may use the # (hash character) in the Python programs. For multi-line comments, use the triple quoted strings. Both of these ways are explained.

The Python switch case statement?

Python switch case

The official site suggests using the if…elif…elif..else statements for the limited number of possibilities (say up to 12 or so). However, for a very large number of possibilities, you may create a dictionary.

What is Python startswith method?

Python startswith

The startswith is a string method that returns True if the specified string starts with the given prefix. In order to check the suffix from last of the string, use the endswith method.