- 2
Pls what is the meaning of %in python
5 ответов
+ 2
You can check this lesson:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/4430/?ref=app
+ 1
depends where you use it. it can mean remainder as in 10 % 3 = 1 where 1 is the remainder
its also used with c style formatting (but you're better off using f strings)
+ 1
To get the remainder of a division, Python 3 uses the percent symbol "%". Remainder is the part of the number remaining after integer division. The operation of taking the remainder is used to solve various types of problems.
For exemple:
print (10 % 3)
# Output: 1
The determination of the remainder of a division is very often used in programs to find, say, even numbers. Or, for example, if data processing is performed in a loop
Learn: https://realpython.com/python-modulo-operator/
+ 1
The % operator is generally used to show the remainder of a certain division.
For example, in python 3.x if you have 21 / 3, it will give 7.0, so it returns the whole result, not just the quotient as happens in python 2.x :
print(21 / 3)
or
print(21/4)
But the expression : 21 % 3 will return 0 as it returns the remainder of this division. This operator will always return an integer :
print(21 % 3)
or
print(21%4)
In the other hand, it is used as an format operator in strings to make a format process just like in C language.
For example:
print('%d \n%f \n%.5f \n%X \n%s \n%s'% (1,2,1/3,123,'hi',['t','h','e','r','e']))
This will print all the arguments is their correspondent order in the terminal.
This type of formatting is used least, as for this purpose is used the .format() method of strings, making string formatting more pythonic 😁.
0
You can also read at this link below for more info :
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-string-formatting/