Python3 basis function parameters specified parameter type in a case where the default value

  •        Python : 3.7.3
  •          OS: Ubuntu 18.04.2 LTS
  •         IDE : pycharm-community-2019.1.3
  •       Conda: 4.7.5
  •    typesetting : Markdown

code

"""
@Author : 行初心
@Date   : 2019/7/4
@Blog   : www.cnblogs.com/xingchuxin
@Gitee  : gitee.com/zhichengjiu
"""


def show(name: str = "python"):
    # 想:有缺省值的参数能不能再指明一下类型呢?
    # 毕竟,代码要给其他人看的,多留一些关键信息,或许会好一点吧。
    # 第一次写时 -> def show(name="python": str) 报错.
    # 开始运用想象力与创造力,写出来了.
    # o(* ̄︶ ̄*)o
    print(name)


def main():
    show()
    show("golang")


if __name__ == '__main__':
    main()

result

/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/Base/demo.py
python
golang

Process finished with exit code 0

resource

  • [Documents - English] docs.python.org/3
  • [Documentation - Chinese] docs.python.org/zh-cn/3
  • [Specification] www.python.org/dev/peps/pep-0008
  • [Specification] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [Source] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [Platform] www.cnblogs.com
  • [Platform] gitee.com


Python has an open source, cross-platform, interpreted, interactive and other characteristics, it is worth learning.
Python's design philosophy: elegant, clear and simple. Promote the use of a method, the best is only one way to do a thing.
Writing code to comply with norms, which helps communication and understanding.
Each language has unique ideas, beginners need to change the thinking, pragmatic practice, adhere to accumulate.

Guess you like

Origin www.cnblogs.com/xingchuxin/p/11135305.html