What is ‘None’ – the equivalent of Null in Python?
In Python, there is no such keyword as null. Instead, you may use the ‘None’ keyword, which is an object. This is how you may assign the ‘none’ to a variable in Python:
In Python, there is no such keyword as null. Instead, you may use the ‘None’ keyword, which is an object. This is how you may assign the ‘none’ to a variable in Python:
What is Python dictionary? The dictionary is a data type in Python that is used to store data in key/value pairs. If you have worked in other languages like PHP, you have worked with associative arrays; the dictionary is like that. A dictionary can be created as follows: telephone_dir = {‘Mike’: 123445689,’Haynes’: 45678910, ….} … Read more
The print function in Python is used to display the output of variables: strings, lists, tuples, ranges, etc. Before version 3.x of Python, the print was taken as a statement. However, from Python 3.x, the print acts as a function. That also means you need to enclose the objects in parenthesis. For example, print (“A … Read more
How to convert Python string to an int and float In certain scenarios, you may need to convert a string to an integer or float for performing certain operations in Python. If you try doing some action with a “string number” like addition, or subtraction, it will generate an error as shown below. The code … Read more
Converting String to int in Python In Python, you may convert an int to a string in different ways. For example: str() Function format() Method f-string join() function- For list of int In this tutorial, we will show you examples of a few ways. The str function in Python The str function of Python can … Read more
What is replace method and how to use it? The Python string replace method is used to “replace” the new substring with the existing substring in the specified string. The replace method returns a copy of the string with replaced substring(s). The source string remains unchanged after using the replace method. Replace function is case-sensitive. See the … Read more
The Python split method is used to break a given string by the specified delimiter like a comma. The method returns a list of words that are broken from the specified separator (delimiter string).
The set in Python Python has a data type for creating sets in its programs. A set is a collection of unordered items that can be created by using curly brackets {}. By unordered, it means the position of the elements in a set is not recorded. And so, you may not perform indexing, slicing … Read more
What is the tuple in Python? The tuple is a compound data type in Python which is immutable. A tuple is a sequence just like we learned in the list chapter. However, the difference between the two is, the tuple is immutable while lists are mutable. That means, once created, a tuple cannot b e changed … Read more
What is list comprehension in Python? List comprehension is the concise and expressive way of creating lists in Python. Generally, list comprehension involves creating a new list where each item of another list or sequence is gone through a certain operation (like square, cube, etc). We will show you examples that how you may create … Read more
The list is a compound data type that is mutable sequences. Among the other compound data types, the lists are the most versatile.
The while loop in Python In the for loop chapter, we learned how to use the for loop with examples. I also explained, the for loop is used when you know the number of iterations. The while loop is used to iterate through the given code for an infinite number. You may also use for … Read more
The purpose of range function in Python The range is a built-in function in Python that represents an immutable sequence of numbers. Generally, Python range is used in the for loop to iterate a block of code for a given number of times. For example, you may create a range of five numbers and use … Read more
The for loop in Python The Python for loop is the way of executing a given block of code repeatedly to a given number of times. In Python, the for loop iterates over the items of a given sequence. The items can be strings unlike in Pascal where it iterates over the arithmetic progression of … Read more
The if statement in Python The if..else and elif are the decision-making statements in Python. It will execute single or more statements based on the given expression. If the given expression is True, the statement inside the if statement will execute. If the condition is false, the statement inside the else will execute. Syntax of … Read more