Python Programming, 1/e 1Python Programming:An Introduction puter ScienceChapter 6Defining FunctionsPython Programming, 1/e 2Objectives To understand why programmers divideprograms up into sets of cooperatingfunctions. To be able to define new functions inPython. To understand the details of functioncalls and parameter passing in Python./ 天津塔吊租赁,河北塔吊租赁,西安塔吊租赁,塔吊租赁 hon Programming, 1/e 3Objectives (cont.) To write programs that use functions toreduce code duplication and increaseprogram Programming, 1/e 4The Function of Functions So far, we’ve seen four different typesof functions: Our prise a single functioncalled main(). Built-in Python functions (abs) Functions from the standard libraries() Functions from the graphics module(())Python Programming, 1/e 5The Function of Functions In the code on page 166, the code fordrawing the bars occurs in two differentplaces. The first bar is drawn immediately beforethe loop. The remaining bars are drawn within Programming, 1/e 6The Function of Functions Having similar or identical code in morethan one place has some drawbacks. Issue one: writing the same code twice ormore. Issue two: This same code must bemaintained in two separate places. Functions can be used to reduce codeduplication and make programs moreeasily understood and Programming, 1/e 7Functions, Informally A function is like a subprogram, a smallprogram inside of a program. The basic idea – we write a sequence ofstatements and then give that sequencea name. We can then execute thissequence at any time by referring tothe Programming, 1/e 8Functions, Informally The part of the program that creates afunction is called a function definition. When the function is used in a program,we say the definition is called Programming, 1/e 9Functions, Informally Happy Birthday lyrics…def main():print "Happy birthday to you!"print "Happy birthday to you!"print "Happy birthday, dear Fred..
计算机编程简介 来自淘豆网www.taodocs.com转载请标明出处.