Python的人会很不习惯Python没有main主函数。
这里简单的介绍一下,在Python中使用main函数的方法

  1. #hello.py   
  2. def foo():   
  3.     str="function"   
  4.     print(str);   
  5. if __name__=="__main__":   
  6.     print("main")   
  7.     foo()

其中if __name__=="__main__":这个程序块类似与Java和C语言的中main(主)函数
在Cmd中运行结果
C:\work\python\divepy>python hello.py
main
function

 

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2021-07-21
  • 2021-08-22
猜你喜欢
  • 2021-07-23
  • 2022-12-23
  • 2022-01-06
  • 2021-12-03
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案