Presentation is loading. Please wait.

Presentation is loading. Please wait.

OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.

Similar presentations


Presentation on theme: "OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions."— Presentation transcript:

1 OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions

2 OCR Computing GCSE © Hodder Education 2013 Slide 2 Python 3: Built-in functions A function is a package of code. It usually returns a value. Python has lots of built-in functions. They have names. They have brackets to hold any arguments passed to them. A common one is print():

3 OCR Computing GCSE © Hodder Education 2013 Slide 3 Python 3: Built-in functions Suppose we give the variable a the value 5 a=5 Then we type: print (a) Python outputs 5 Print(‘a’) Python outputs a The quote signs tell print() to output the letter a, not the variable.

4 OCR Computing GCSE © Hodder Education 2013 Slide 4 Python 3: Built-in functions The len() function This tells us the length of something. It can be a string. (a string is a sequence of characters) If we type length=len(‘hello’) Python outputs 5.

5 OCR Computing GCSE © Hodder Education 2013 Slide 5 Python 3: Built-in functions len() can also tell us the size of other Python objects. Later we shall see that it can tell us the number of elements in a list or a tuple. e.g. Here is a list stored in the variable movie. movie=['Skyfall','PG','26/10/2012',143] If we then print(len(movie)) Python outputs 4 because there are 4 items in the list. We can embed functions in each other. Notice that the len() function is embedded in the print() function.

6 OCR Computing GCSE © Hodder Education 2013 Slide 6 Python 3: Built-in functions Another function: sorted() You can see all the built-in functions at: http://docs.python.org/2/library/functions.html


Download ppt "OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions."

Similar presentations


Ads by Google