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

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).
主站蜘蛛池模板: 湘阴县| 东平县| 临高县| 安溪县| 镇雄县| 调兵山市| 招远市| 顺义区| 高安市| 米林县| 化德县| 灵璧县| 江永县| 江北区| 尼玛县| 宣化县| 辽宁省| 五寨县| 宝坻区| 静安区| 海晏县| 吴旗县| 桑日县| 嘉鱼县| 余干县| 乐亭县| 甘孜县| 翁源县| 金湖县| 安宁市| 宜宾市| 临猗县| 巴南区| 林口县| 贵德县| 西乡县| 德化县| 岚皋县| 东兰县| 宁晋县| 金沙县|