Blog

python tutorials and learn python

Created with Sketch.

Python Iterables

Python Iterables Summary: in this tutorial, you’ll learn about the Python iterables and iterators. Introduction to Python iterables In Python, an iterable is an object that includes zero, one, or many elements. An iterable has the ability to return its elements one at a time. Because of this feature, you can use a for loop…
Read more

How to Find the Index of an Element in a List

How to Find the Index of an Element in a List   Summary: in this tutorial, you’ll learn how to find the index of an element in a list. To find the index of an element in a list, you use the index() function. The following example defines a list of cities and uses the…
Read more

How to Use a For Loop to Iterate over a List

How to Use a For Loop to Iterate over a List Summary: in this tutorial, you’ll learn how to use the Python for loop to iterate over a list in Python. Using Python for loop to iterate over a list To iterate over a list, you use the for loop statement as follows: for item…
Read more

How to Unpack a List in Python

How to Unpack a List in Python Summary: in this tutorial, you’ll learn how to unpack a list in Python to make your code more concise. Introduction to the list unpacking The following example defines a list of strings: colors = [‘red’, ‘blue’, ‘green’] Code language: Python (python) To assign the first, second, and third…
Read more

Python List Slice

Python List Slice   Summary: in this tutorial, you’ll learn about Python list slice and how to use it to manipulate lists effectively. Introduction to Python List slice notation Lists support the slice notation that allows you to get a sublist from a list: sub_list = list[begin: end: step] Code language: Python (python) In this…
Read more

Python sorted

Python sorted Summary: in this tutorial, you’ll learn how to use the Python sorted() function to sort a list. Introduction to the Python sorted() function The sort() method sorts a list in place. In other words, it changes the order of elements in the original list. To return the new sorted list from the original…
Read more

Python Sort List

Python Sort List   Summary: in this tutorial, you’ll learn how to use the Python List sort() method to sort a list. Introduction to the Python List sort() method To sort a list, you use the sort() method: list.sort() Code language: Python (python) The sort() method sorts the original list in place. It means that…
Read more

Python Tuples

Python Tuples Summary: in this tutorial, you’ll learn about Python tuples and how to use them effectively. Introduction to Python tuples Sometimes, you want to create a list of items that cannot be changed throughout the program. Tuples allow you to do that. A tuple is a list that cannot change. Python refers to a…
Read more

Python List

Python List Summary: in this tutorial, you’ll learn about Python List type and how to manipulate list elements effectively. What is a List A list is an ordered collection of items. Python uses the square brackets ([]) to indicate a list. The following shows an empty list: empty_list = [] Code language: Python (python) Typically,…
Read more

Python Function Docstrings

Python Function Docstrings Summary: in this tutorial, you’ll learn about how to use docstrings to add documentation to a function. Introduction to the help() function Python provides a built-in function called help() that allows you to show the documentation of a function. The following example shows the documentation of the print() function: help(print) Code language:…
Read more