IndentationError: unexpected indent Python timeit() Method
IndentationError: unexpected indent Python timeit() Method
我是 python 的新手,当时正在学习时间复杂度概念,了解 time() 和 timeit() 方法。当我尝试执行下面的程序时出现错误 "IndentationError: unexpected indent"。有人可以阐明这里的问题吗
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")
你的缩进有点不对
而不是:
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")
尝试:
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")
我是 python 的新手,当时正在学习时间复杂度概念,了解 time() 和 timeit() 方法。当我尝试执行下面的程序时出现错误 "IndentationError: unexpected indent"。有人可以阐明这里的问题吗
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")
你的缩进有点不对
而不是:
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")
尝试:
import timeit
setup_code = "from math import factorial"
statement="""for i in range(10):
factorial(i)"""
print(f"Execution time is: {timeit.timeit(setup = setup_code, stmt = statement, number = 10000000)}")