Writing Comments in Python
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.
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 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.
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.
In Python, you may use the equal to (==) and not equal to (!=) operators for testing the equality of two objects.
The ‘not’ is a Logical operator in Python that will return True if the expression is False. The ‘not’ operator is used in the if statements.
The ‘or’ in Python is a logical operator that evaluates as True if any of the operands is True, unlike the ‘and’ operator where all operands have to be True.
In Python, the ‘and’ is a logical operator that evaluates as True if both the operands (x and y) are True.
One way is using the comparison operators == and != (equal to and not equal to). A few other methods are also explained in the later part of this tutorial.
Python has built-in functions for converting the case of all letters in a given string. These functions are lower() and upper(). Keep reading for examples with code.
How to reverse strings in Python There is no specific method of the str object to reverse a string in Python like the list reverse method, you may use a number of techniques to reverse a string. One of the ways is using the extended slice. The second way the is reversed() method with join() … Read more
the Python isinstance() function is used to test the type of an object. For example, testing the type of list, tuple, dictionary, integer, float etc.
By passing the object to the type() function, the single required parameter, it returns the type of the object like a list, integer, float, tuple etc.
The find() method returns the index number of the first occurrence of the given search term in the specified string. If the specified string does not contain the search term, the find() returns -1.
The slicing is a Python methodology that enables accessing parts of data from the given sequence like lists, tupes, strings etc. and objects that support sequence protocol.
The continue statement is used in the for and while loops in Python to omit the execution for current iteration. Any statements after the continue statement within the loop will be neglected and execution…