CP104 Lecture Notes - Lecture 2: Local Variable, Return Statement, Memory Management
Sept. 25 2017
Chapter 5
Topic 4 :functions
A library function is viewed as a black box
Standard library functions and the import statement
- Modules:files that stores functions of the standard library
- To call a function import statement
- In python math library is not loaded in the memory so we need an import
statement (import math) and puts them in the memory
> import math
> math.sqrt(25)
>>5.0
math.ceil(16.9
>17
math.ceil(16.1)
>17
help(math.ceil)>> to know what the function does
Documentation of all functions in math module
- Math module in python standard library
-
Decomposition
-Break the problem into different independant smaller pieces (main program, function q,
2,3 ect.))
Abstration
-
Introduction of Functions
Function: group of statements within a program that performs a specific task
Python Functions
- Built in functions that are provided in python such at int(), input()
hayjayshay and 38575 others unlocked
2
CP104 Full Course Notes
Verified Note
2 documents
Document Summary
A library function is viewed as a black box. Modules:files that stores functions of the standard library. In python math library is not loaded in the memory so we need an import statement (import math) and puts them in the memory. >17 help(math. ceil)>> to know what the function does. Break the problem into different independant smaller pieces (main program, function q, Function: group of statements within a program that performs a specific task. Built in functions that are provided in python such at int(), input() Hello cp106 week 7 hello cp104 greetings() print( week 7") greetings() (go to visualize python to see) >return x_cube x=5 y=cube(x) print( {} **3= {}" . format(x,y)) After the return statement there can be no statement because you have already left the function. Function: a reusable code that takes arguments y=cube(5) (5)--> arguments y= assignment i= 5 k=14 compute(i,k,20)