Py4Inf-04-Functions-PrintPy4Inf-04-Functions-Print
6页1、FunctionsChapter 4Python for Informatics: Exploring IUnless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License.htp:/creativecommons.org/licenses/by/3.0/.Copyright 2010- Charles R. SeveranceStored (and reused) StepsOutput:HelloFunZipHelloFunProgram:def hello():print Helloprint Funhello()print Ziphello()defprint Helloprint Funhello()print “Zip”We cal these reusable pieces of code “functions”.hello():hello()Python FunctionsThere are two
2、 kinds of functions in Python.Built-in functions that are provided as part of Python - raw_input(), type(), float(), int() .Functions that we define ourselves and then useWe treat the of the built-in function names as new reserved words (i.e. we avoid them as variable names)Function DefinitionIn Python a function is some reusable code that takes arguments(s) as input does some computation and then returns a result or resultsWe define a function using the def reserved wordWe cal/invoke the functi
3、on by using the function name, parenthesis and arguments in an expression big = max(Hello world) print bigw tiny = min(Hello world) print tinybig = max(Hello world)ArgumentwResultAssignmentMax Function big = max(Hello world) print bigwmax()function“Hello world” (a string)w(a string)A function is some stored code that we use. A function takes some input and produces an output.Guido wrote this codeMax Function big = max(Hello world) print bigwdef max(inp):blahblahfor x in y:blahblah“Hello world” (
4、a string)w(a string)A function is some stored code that we use. A function takes some input and produces an output.Guido wrote this codeType ConversionsWhen you put an integer and floating point in an expression the integer is implicitly converted to a floatYou can control this with the built in functions int() and float() print float(99) / 1000.99 i = 42 type(i) f = float(i) print f42.0 type(f) print 1 + 2 * float(3) / 4 - 5-2.5 String ConversionsYou can also use int() and float() to convert be
《Py4Inf-04-Functions-PrintPy4Inf-04-Functions-Print》由会员海天分享,可在线阅读,更多相关《Py4Inf-04-Functions-PrintPy4Inf-04-Functions-Print》请在金锄头文库上搜索。
红灰动态个性商务幻灯片模板简洁动态手势
蓝色清爽月度工作总结PPT模板简洁商务办公月度总结
动态蓝色拼图背景的工作计划PPT模板工作计划2
高架桥背景的工作计划PPT模板
Excel函数VBA教程基础入门(下)
唯美蓝色星空背景的动态工作总结PPT模板蓝色星空2
繁华城市背景的商业融资计划书PPT模板繁华城市
红灰动态个性商务幻灯片模板红灰个性商务
Py4Inf-06-Strings-PrintPy4Inf-06-Strings-Print
Py4Inf-05-IterationsPy4Inf-05-Iterations
Py4Inf-05-Iterations-PrintPy4Inf-05-Iterations-Print
Py4Inf-04-FunctionsPy4Inf-04-Functions
Py4Inf-04-Functions-PrintPy4Inf-04-Functions-Print
Py4Inf-03-ConditionalPy4Inf-03-Conditional
Py4Inf-03-Conditional-PrintPy4Inf-03-Conditional-Print
Py4Inf-02-ExpressionsPy4Inf-02-Expressions
Py4Inf-02-Expressions-PrintPy4Inf-02-Expressions-Print
Py4Inf-01-IntroPy4Inf-01-IntroPy4Inf-01-IntroPy4Inf-01-Intro
Py4Inf-01-Intro-PrintPy4Inf-01-Intro-Print
JAVA初级入门教程
2024-03-05 77页
2024-03-05 50页
2024-02-29 54页
2024-02-29 75页
2024-02-29 52页
2024-02-29 54页
2024-02-29 125页
2024-02-29 74页
2024-02-29 61页
2024-02-29 56页