Skip to content
CBT Nuggets
DemoBook a Demo

Understand Functions in Python

This skill, led by John McGovern, delves into the fundamental concepts of using functions in Python. It covers the creation and utilization of Python functions, including built-in and custom functions. Key topics include the use of positional, default, and keyword arguments, as well as the importance of the return statement for returning values from functions. The skill emphasizes writing modular, reusable code and adhering to best practices such as the DRY principle.

Full skill from Python Functions. Preview the training IT teams trust.

Updated

54m

Skill 1 of 16 in Python Functions

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!

Video unavailable

Exploring Built-In Functions

In this Nugget we take a look at some of Python's built-in functions!

Video unavailable

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!

Video unavailable

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!

Video unavailable

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!

Video unavailable

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.

What's next?

Ready to keep going?

For your team

Bring this training to your team

See how CBT Nuggets helps IT teams close skills gaps, hit compliance targets, and prove training ROI.

Book a Demo
Just need Python Functions?

Learning on your own? Browse individual plans ($49/month, billed annually) →

Not ready to buy?
with no purchase required. Already have an account?
Book a Demo