Python Dictionary: Explained with 11 Examples

An infographic tutorial that helps you master Python dictionaries. Learn to create, manipulate, and and use methods of dictionaries and other useful information.

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

Python 3 print function

Python print

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

Convert a Python String to int and float

Infographic: Converting Python String to Integer and Float - A visual guide illustrating how to convert Python strings to integer and floating-point numbers using int() and float() functions.

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

How to Convert Python int to string

An graphic showing how to convert into to string in Python. Learn to use str() function, f-string, format() method etc. by visual graphic.

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

Python String Replace Method

Infographic: Python String Replace - Visual guide demonstrating the Python string replace method, illustrating how it replaces specified substrings with new text within a given string

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

How to create and use Python set: 7 examples

Python set length

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

Python Tuple: Explained with 9 examples

Python tuple strings

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

Understand Python List Comprehensions

A visual guide to understand list comprehension in Python. Learn the syntax, features, use cases and an example.

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

Learn using Python for loop: 7 examples

Python for loop multiple

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

Python if, else and elif statements: Explained with 8 examples

Python if else

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