程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] operator

編輯:Python

Arithmetic operator

Operator explain + The number type indicates addition , The string type represents the concatenation - The number type indicates subtraction * The number type represents multiplication , The string represents repeated output / Number type indicates Division // The numeric type represents an integer division ** Numeric types represent power functions ( namely n Power )% The numeric type represents remainder

Example

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" @file: The_Operator.py @author: Henry @datetime: 2022/6/25 0025 22:41 """
a = 9
b = 2
c = 'Hello '
d = 'Henry'
# String addition 
print(c+d)
# String multiplication 
print(c*2)
# division 
print(a/b)
# to be divisible by 
print(a//b)
# power function 
print(a**b)
# Remainder 
print(a%b)

Assignment operator

Operator explain = Assign the value on the right side of the operator to the variable on the left += The variable on the left side of the operator matches the expression on the right side of the operator Add , Then assign the result to the variable to the left of the operator -= The variable on the left side of the operator matches the expression on the right side of the operator reduce , Then assign the result to the variable to the left of the operator *= The variable on the left side of the operator matches the expression on the right side of the operator ride , Then assign the result to the variable to the left of the operator /= The variable on the left side of the operator matches the expression on the right side of the operator except , Then assign the result to the variable to the left of the operator //= Variable to the left of operator to be divisible by The expression to the right of the operator , Then assign the result to the variable to the left of the operator **= The variable on the left side of the operator is used for the expression on the right side of the operator The next power Then assign the result to the variable on the left of the operator again %= The variable on the left of the operator and the expression on the right of the operator Remainder Then assign the result to the variable on the left of the operator again
a = 9
b = 2
a /= b
print(a, b)
a = 9
b = 2
a //= b
print(a, b)
a = 9
b = 2
a **= b
print(a, b)
a = 9
b = 2
a %= b
print(a, b)

Relational operator

Operator explain > Greater than < Less than >= Greater than or equal to <= Less than or equal to == equal != It's not equal

Logical operators

Operator explain and Yes FALSE be FALSE, On both sides TRUE Then return to TRUEor Yes TRUE be TRUE, On both sides FALSE Then return to FALSEnot Take the opposite


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved