What you'll learn
- Explain how a reusable function lets you change logic in one place and call it as many times as needed in a script
- Use the help() function to explore Python built-in functions such as print(), including its sep and end arguments
- Create a function with the def keyword using lowercase, underscore-separated naming and the correct parentheses and colon syntax
- Document a function with a docstring and display it using help() or by printing the function's __doc__ attribute
- Compare positional, default, and keyword arguments by passing platform and hostname values to a device configuration function
- Write a function that returns a generated value, such as an email address built from a username and a default provider
Free 54-minute video lesson with a full transcript and knowledge checks. No account needed to watch.
Overview
Join John McGovern as he covers the fundamental concepts around the use of functions within Python.
Recommended Experience
- At least six months of Python programming experience is recommended, but not required
- An understanding of concepts taught in Cisco CCNA is recommended, but not required
Related Job Functions
- Network engineer
- DevOps engineer
John McGovern has been a CBT Nuggets trainer since 2020. His areas of expertise include Python, networking, network automation, and cybersecurity.
Introduction to Functions
In this Nugget we take an introductory look at functions within Python!
Exploring Built-In Functions
In this Nugget we take a look at some of Python's built-in functions!
Knowledge Check
Which of the following is a parameter, used by the built-in print function, that will add a separator between strings to be printed?
Creating Functions
In this Nugget we learn how to create our own custom functions!
Knowledge Check
Which of the following is a keyword used to create a new user defined function?
Passing Arguments
In this Nugget we learn how to leverage positional, default, and keyword arguments within our functions!
Knowledge Check
Positional arguments cannot follow keyword arguments. True or false?
The Return Statement
In this Nugget we learn how to use the "return" keyword within our functions!
Knowledge Check
A Python function will return which value by default?
Conclusion
I hope this has been informative for you and I would like to thank you for consuming.
Frequently asked questions
What does the Understand Functions in Python lesson cover for network engineers?
The learner on your team defines functions with the def keyword using lowercase, underscore-separated names, then documents them with docstrings and explores built-in functions like print() with help(). The lesson also compares positional, default, and keyword arguments using a device configuration function, and covers return statements that generate values such as an email address.
How long is the Python functions lesson and where does it fit in the Python for Network Engineers course?
The lesson runs 54 minutes inside a course that represents about 22 hours per learner. The course starts with Python fundamentals and data structures, then moves through functions, text files, network automation libraries, Jinja templates, REST APIs, spreadsheets, troubleshooting, testing, and concurrent connections.
Who is the Python for Network Engineers course designed for?
IT Directors can assign it to network administrators with 1 to 3 years of networking experience but little or no Python background who need a practical path into automation. Team Leads can use it as a baseline before asking staff to contribute automation scripts in production environments.
What is the difference between positional, default, and keyword arguments in a Python function?
With positional arguments the order you pass values is vital, while a default argument uses an equal sign in the function definition, such as assuming the platform is Cisco unless another value is supplied. Keyword arguments map each value to a named parameter, so platform, hostname, and username can be passed in any order, and the lesson shows these approaches can be mixed.
How do you view a Python function's docstring?
You can pass the function to help() or print the function's __doc__ attribute. Printing sends the docstring straight to the terminal, while help() opens it in a pager, which is handy for long docstrings.
How can a Training Manager track team progress through this Python course?
Team reporting provides per-learner progress and completion, cohort and group views, and completion exports for audit evidence. Training Managers can also use Playlists to sequence this course with related automation training.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
Python
Python Functions
Assign the full course, track completion, and connect this skill to your team's readiness plan.
Python
Python Network Automation
Assign the full course, track completion, and connect this skill to your team's readiness plan.
For teams
Build a path around this skill
See how courses, reporting, labs, and IT Trainerbot fit your rollout.
Free training library
More free lessons in Python
Python
Introduction to Programming and Python
Free lesson from Certified Associate in Python Programming (PCAP) · 57m
Python
Introduction to Python
Free lesson from Python for Network Engineers · 59m
Python
Build Webservers with Flask: The Basics
Free lesson from Python Flask Tutorial · 51m
Python
Understand Object-Oriented Programming Basics
Free lesson from Certified Professional in Python Programming 1 (PCPP1) · 1h 4m
Python
Writing and Running Python Code
Free lesson from Certified Entry-Level Python Programmer (PCEP™) · 1h 4m
Python
Intermediate Behavior-Driven Development Concepts
Free lesson from Certified Associate Tester with Python (PCAT™) · 51m
$59
seat / mo, billed annually
