官术网_书友最值得收藏!

Functions

A function is a block of organized, self-contained programs that perform a specific task, which you can incorporate into your own larger programs. They are defined as follows:

    # function 
    def  functionname(): 
      do something 
      return 

These are a few points to remember:

  • Indentation is very important in Python programs
  • By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined in

Please see the following code snippet example, which showcases functions:

    def display ( name ): 
    #This prints a passed string into this function 
      print ("Hello" + name) 
      return;

You can call the preceding function as follows:

    display("Manish") 
    display("Mohit") 

The following screenshot shows the execution of the preceding display function:

Note that if you have more than one Python version installed on your system, you need to use Python 3 instead of Python, which uses the default version of Python (generally, 2.7.x).
主站蜘蛛池模板: 民县| 福州市| 开远市| 城口县| 仁怀市| 广德县| 库车县| 五莲县| 乌苏市| 两当县| 云安县| 达拉特旗| 普陀区| 涪陵区| 广饶县| 平舆县| 镇宁| 平度市| 大冶市| 蓬溪县| 简阳市| 临夏县| 永仁县| 云南省| 尖扎县| 永平县| 苍溪县| 岚皋县| 昔阳县| 太湖县| 云霄县| 新建县| 丰镇市| 忻城县| 富锦市| 北京市| 军事| 新乐市| 石门县| 乌审旗| 广东省|