RUVIDEO
Поделитесь видео 🙏

Modulos function in Python

📁 Обучение 👁️ 17 📅 03.12.2023

The Python Modulo Operator - What Does the % Symbol Mean in Python? 

When you see the % symbol, you may think "percent". But in Python, as well as most other programming languages, it means something different.

The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand. It's used to get the remainder of a division problem.

The modulo operator is considered an arithmetic operation, along with +, -, /, *, **, //.

The basic syntax is:

a % b

In the previous example a is divided by b, and the remainder is returned. Let's see an example with numbers.
the previous example a is divided by b, and the remainder is returned. Let's see an example with numbers.

7 % 2

The result of the previous example is one. Two goes into seven three times and there is one left over.

The diagram below shows a visual representation of 7 / 2 and 7 % 2 (The "R" stands for "remainder"). The single logo on the right side (with the green arrow pointing at it) is the remainder from the division problem. It is also the answer to 7 % 2.

This will result in three. Four does not go into three any times so the original three is still left over. The diagram below shows what is happening. Remember, the modulo operator returns the remainder after performing division. The remainder is three.





Python Modulo in Practice: How to Use the % Operator

by Jason Van Schooneveld 8 Comments  basics python

Mark as Completed

Tweet Share Email

Table of Contents

Modulo in Mathematics

Python Modulo Operator Basics

Modulo Operator With int

Modulo Operator With float

Modulo Operator With a Negative Operand

Modulo Operator and divmod()

Modulo Operator Precedence

Python Modulo Operator in Practice

How to Check if a Number Is Even or Odd

How to Run Code at Specific Intervals in a Loop

How to Create Cyclic Iteration

How to Convert Units

How to Determine if a Number Is a Prime Number

How to Implement Ciphers

Python Modulo Operator Advanced Uses

Using the Python Modulo Operator With decimal.Decimal

Using the Python Modulo Operator With Custom Classes





Python Modulo in Practice: How to Use the % Operator

by Jason Van Schooneveld 8 Comments  basics python

Mark as Completed

Tweet Share Email

Table of Contents

Modulo in Mathematics

Python Modulo Operator Basics

Modulo Operator With int

Modulo Operator With float

Modulo Operator With a Negative Operand

Modulo Operator and divmod()

Modulo Operator Precedence

Python Modulo Operator in Practice

How to Check if a Number Is Even or Odd

How to Run Code at Specific Intervals in a Loop

How to Create Cyclic Iteration

How to Convert Units

How to Determine if a Number Is a Prime Number

How to Implement Ciphers

Python Modulo Operator Advanced Uses

Using the Python Modulo Operator With decimal.Decimal

Using the Python Modulo Operator With Custom Classes

Conclusion



 Remove ads

 Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Python Modulo: Using the % Operator

Python supports a wide range of arithmetic operators that you can use when working with numbers in your code. One of these operators is the modulo operator (%), which returns the remainder of dividing two numbers.

In this tutorial, you’ll learn:

How modulo works in mathematics

How to use the Python modulo operator with different numeric types

How Python calculates the results of a modulo operation

How to override .__mod__() in your classes to use them with the modulo operator

How to use the Python modulo operator to solve real-world problems

The Python modulo operator can sometimes be overlooked. But having a good understanding of this operator will give you an invaluable tool in your Python tool belt.





Example using the Modulo Operator

One common use for the Modulo Operator is to find even or odd numbers. The code below uses the modulo operator to print all odd numbers between 0 and 10.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Modulos function in Python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.