def imports():
import time
global time.sleep()
def title_screen():
print("Welcome to Text RPG")
print("Created by: Nick Giesler")
print("")
input("Press ENTER to Begin:")
print("Loading...")
time.sleep(1)
imports()
title_screen()
运行时,会返回指向“global time.sleep()
”的无效语法:
Traceback (most recent call last):
File "python", line 3
global time.sleep()
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
只有identifier
(s)可以跟the global statement:
global_stmt ::= "global" identifier ("," identifier)*
其中标识符是普通名称,例如:
a = 20
b = "string"
global a, b
当您违反该要求并且python无法在global
之后找到标识符时,SyntaxError
将会被提升。
global
关键字不是标识符后您输入的内容;它是a function call,它在标识符之后被()
语法识别。