Category: New Python tutorial

python tutorials and learn python

Created with Sketch.

Python iter

Python iter Summary: in this tutorial, you’ll learn how to use the Python iter() built-in function effectively. Introduction to the Python iter function The iter() function returns an iterator of a given object: iter(object) Code language: Python (python) The iter() function requires an argument that can be an iterable or a sequence. In general, the…
Read more

Python Iterator vs Iterable

Python Iterator vs Iterable Summary: in this tutorial, you’ll learn about Python iterator and iterable and their differences. Iterators An iterator is an object that implements the iterator protocol. In other words, an iterator is an object that implements the following methods: __iter__ returns the iterator object itself. __next__ returns the next element. Once you…
Read more

Python Iterators

Python Iterators Summary: in this tutorial, you’ll learn about Python iterator and how to define a custom iterator using the iterator protocol. What is a Python iterator? An iterator is an object that implements: __iter__ method that returns the object itself. __next__ method that returns the next item. If all the items have been returned,…
Read more

Python Fibonacci Sequence

Python Fibonacci Sequence Summary: in this tutorial, you’ll learn how to define a custom Sequence type in Python and how to implement the Fibonacci sequence using a custom Sequence type. Introduction to the custom Sequence type in Python Sometimes, it’s useful to implement a custom sequence type that has functions similar to the built-in sequence…
Read more

Python Slicing in Depth

Python Slicing in Depth Summary: in this tutorial, you’ll learn about Python slicing and how to use it to extract data from and assign data to a sequence. Python slicing review So far you’ve learned about slicing such as list slicing. Technically, slicing relies on indexing. Therefore, slicing only works with sequence types. For mutable…
Read more

Python Tuple vs. List

Python Tuple vs. List Summary: in this tutorial, you’ll learn the difference between tuple and list. Both tuple and list are sequence types. However, they have some main differences. 1) A tuple is immutable while a list is mutable The following example defines a list and modifies the first element: fruits = [‘apple’, ‘orange’, ‘banana’]…
Read more

Python Sequences

Python Sequences Summary: in this tutorial, you’ll learn about the Python sequences and their basic operations. Introduction to Python sequences A sequence is a positionally ordered collection of items. And you can refer to any item in the sequence by using its index number e.g., s[0] and s[1]. In Python, the sequence index starts at…
Read more

Python NamedTuple

Python NamedTuple Summary: in this tutorial, you’ll learn how to use the Python namedtuple function to create named tuples. Introduction to Python named tuples The following shows a tuple that has two elements: point = (100,200) Code language: Python (python) The point tuple represents a 2D point whose x-coordinate is 100 and y coordinate is…
Read more

Python Class Decorators

Python Class Decorators Summary: in this tutorial, you’ll learn about Python class decorators. After the tutorial, you’ll know how to define classes as decorators. Introduction to the Python class decorators So far you have learned how to use functions to define decorators. For example, the following star function prints out a number of * characters…
Read more

Python Decorator with Arguments

Python Decorator with Arguments Summary: in this tutorial, you’ll learn how to define Python decorators with arguments using a decorator factory. Introduction to Python decorator with arguments Suppose that you have a function called say that prints out a message: def say(message): ”’ print the message Arguments message: the message to show ”’ print(message) Code…
Read more