Page 87 - TP_V5.1_C8_fb
P. 87

Program 1: To print a string by calling a function.

                     Program1.py
                  File  Edit  Format   Run    Options   Window    Help

                  #Function definition
                  def hello (name):
                      print('Hello ' +name+ '! How do you do?')

                  #Calling function by passing parameter
                  hello('Orange')



                 You will get the following output:

                     Output

                  Hello Orange! How do you do?



                 Program 2: To add two numbers using user-defined function.

                     Program2.py
                  File  Edit  Format   Run    Options   Window    Help


                  #Program that demonstrate to create a user-defined function
                  def add (a, b):
                      c = a+b
                      print("The sum of both the numbers is", c)
                  add (12, 16)



                 You will get the following output:

                     Output

                  The sum of both the numbers is 28





                      PURE       1.4% of all  websites  on the Internet use  Python  as a server-side programming
                      FACT       language.






                           STRING

                 A sequence of characters that is enclosed or surrounded by single (‘ ’) or double (“ ”) quotes is

                 known as a string. The sequence may include a letter, number, special characters or a backslash.
                 Python treats single quotes as double quotes.




                                                                                   Functions, String and List in Python  85
   82   83   84   85   86   87   88   89   90   91   92