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

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).
主站蜘蛛池模板: 诸暨市| 尤溪县| 托里县| 郧西县| 同江市| 霍林郭勒市| 客服| 巧家县| 方山县| 炉霍县| 望都县| 建阳市| 南宁市| 英吉沙县| 全椒县| 金秀| 准格尔旗| 苏尼特左旗| 内江市| 台南县| 乐清市| 漳平市| 兰溪市| 瑞丽市| 特克斯县| 昌平区| 视频| 泾源县| 江安县| 西峡县| 孙吴县| 浪卡子县| 新田县| 阜阳市| 习水县| 璧山县| 泰来县| 澎湖县| 马龙县| 乐安县| 体育|