我需要以下句子的解释或例子

问题描述 投票:0回答:1

句子如下。 “算术表达式由常量、变量、两者的组合或由算术运算符连接的函数调用组成”

我需要一个详细说明和一个例子,上面写着“一个函数调用,由算术运算符连接

python operators
1个回答
0
投票
# constants
MY_CONST = True
MAX_COUNT = 10

# variable
some_counter = 0


def my_function():
    global some_counter
    if MY_CONST:  # algorithmic operator if
        some_counter += 1  # algorithmic operator +=
    else:
        some_counter -= 1  # algorithmic operator -=
    if abs(some_counter) == MAX_COUNT:  # abs is another function, == another algorithmic operator
        print('event occurred')
        some_counter = 0  # algorithmic operator =


for _ in range(MAX_COUNT):
    # function call
    my_function()
© www.soinside.com 2019 - 2024. All rights reserved.