python主函数

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:workpythondivepy>python hello.py
main
function

原文地址:https://www.cnblogs.com/zzfighting/p/5502812.html