例如,当我输入"退出"时,我想要显示ascii art message。但是,如果我将它引用到我定义它的位置,那么它会给我一个错误。如果我将它放在参考点之上,那么它可以工作,但它看起来并不是最好的。有没有办法能够在程序看到它之前召唤一个函数?谢谢:))
答案 0 :(得分:1)
不是,但你可以近距离接触:
def main ():
# ... Do things
f ()
# ... Do other things
def f ():
print ('hello')
main ()
答案 1 :(得分:0)
不,但如果你想要,你可以将该功能放在另一个文件中并导入它,以便主文件看起来很漂亮
main.py
from other import exit
# do something
exit()
other.py
def exit():
print("ASCII goodbye")