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

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).
主站蜘蛛池模板: 尉氏县| 三亚市| 岱山县| 大同市| 平乡县| 从江县| 延边| 汽车| 永城市| 石河子市| 韩城市| 西乌珠穆沁旗| 永安市| 富蕴县| 济宁市| 丰原市| 陵水| 永宁县| 松阳县| 那曲县| 澄城县| 宁夏| 大方县| 龙游县| 芮城县| 珲春市| 南召县| 双辽市| 临泉县| 老河口市| 墨竹工卡县| 瓦房店市| 京山县| 桂林市| 自治县| 鄱阳县| 集贤县| 醴陵市| 河北区| 应用必备| 玛沁县|