Today in this article we will talk about python operators, which will be often used in future programming. This operator will be used in future programming and many aspects. There are different operations in it. Talisman can be used in various different aspects, each with its own function. Next, I will take you to learn them. I hope this article can help you reading.
First we need to understandWhat is an operator: Take a simple example 4 5 = 9. In the example, 4 and 5 are called operands, and " " is called the operator.
The Python language supports the following types of operators:
Arithmetic operators
Comparison (relational) operators
Assignment operators
Logical operators
##Bit operators
Member Operator
Identity Operator
Operator Priority
Let’s do it next Let’s learn about these operators one by one.Python arithmetic operators:
Add - Add two objects - Subtract - Get a negative number or subtract one number from another number * Multiply - multiply two numbers or return a string repeated several times / Divide - divide x by y % Modulo - return division Remainder of ** Power-returns the y power of The mathematical operation symbols we usually use are actually very similar and easy to understand. Next, let me give some examples to demonstrate:#!/usr/bin/python # -*- coding: UTF-8 -*- a = 15 b = 30 c = 0 c = a + b print "1 - c 的值为:", c c = a - b print "2 - c 的值为:", c c = a * b print "3 - c 的值为:", c c = a / b print "4 - c 的值为:", c c = a % b print "5 - c 的值为:", c # 修改变量 a 、b 、c a = 2 b = 3 c = a ** b print "6 - c 的值为:", c a = 10 b = 5 c = a // b print "7 - c 的值为:", c
1 - c 的值为: 45 2 - c 的值为: -15 3 - c 的值为: 450 4 - c 的值为: 0 5 - c 的值为: 15 6 - c 的值为: 8 7 - c 的值为: 2
The above is the detailed content of python operators - the most commonly used arithmetic operators (practical summary). For more information, please follow other related articles on the PHP Chinese website!