Functions are a fundamental unit of code in Python. This lesson describes how functions are created, and how they are used.
- [Narrator] Functions in Python serve the purpose of…both functions and subroutines in other languages.…Here in Komodo, I've opened a working copy of function.py…from chapter two of the exercise files…and here we have a very simple function,…with just one line of code in its block.…The function is defined with the D-E-F,…def keyword that defines a function,…then we have the name of the function,…and it will always have parenthesis,…even if it does not take any arguments.…
And any arguments are separated by commas…inside of those parentheses.…And then that argument becomes a variable…within the scope of the function,…and that variable can be printed in this case.…And so, here's the call to the function, the function call,…I have the name of the function,…and then the parentheses again,…they're not optional, even if there's no argument,…and a value.…So here, we're passing the function…the value 47,…and it will print the number 47 when I save and run it.…
And there we have the number 47 in our command output.…So, if I give it a different number, say 12,…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.