各自的作用:

  __doc__:获取到注释内容

  __name__:获取到函数的名称

  __file__:获取到当前的文件路径

 

示例代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:lucky,time:2019-06-10

def my_python():
    """This is my python"""
    return ("From my python!")

print my_python()
print(my_python.__doc__)
print (my_python.__name__)
print __file__

结果展示:

     Python----常用的__doc__、__name__、__file__的使用

 

相关文章:

  • 2021-06-20
  • 2021-06-24
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2021-05-30
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
相关资源
相似解决方案