1. Introduction The programs that we have written so far comprise a single function, usually called main. We have also been using pre-written functions and methods including built-in Python functions (e.g., input, print, range). Functions are an important tool for building sophisticated programs. This lecture covers the whys and hows of designing your own functions to make your programs easier to write and understand.
2. Define, Create and Call Functions You can think of a function as a subprogram-a small program inside a program. Functions are the reusable pieces of code which help us to organize the structure of the code. The basic idea of a function is that we write a sequence of statements and give that sequence a name. The instructions can then be executed at any point in the program by referring to the function name. After all that, now the question is, why write functions? The answer to this question is that the ability to define our own functions helps programmers in two ways. When you are writing a program if you find yourself writing the same code more than once, it is probably best to define a function with the repeated code in it. Then you can call the function as many times as needed instead of rewriting the code again and again.
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|