直接用max函数 import time time_start = time.perf_counter_ns() a = 0 for i in range(1, 10000): a = max(a, i) time_end