Interactive Course

Writing Functions in Python

Learn to use best practices to write maintainable, reusable, complex functions with good documentation.

  • 4 hours
  • 15 Videos
  • 46 Exercises
  • 1,243 Participants
  • 3,650 XP

Loved by learners at thousands of top companies:

dell-grey.svg
whole-foods-grey.svg
lego-grey.svg
ebay-grey.svg
ea-grey.svg
uber-grey.svg

Course Description

You've done your analysis, built your report, and trained a model. What's next? Well, if you want to deploy your model into production, your code will need to be more reliable than exploratory scripts in a Jupyter notebook. Writing Functions in Python will give you a strong foundation in writing complex and beautiful functions so that you can contribute research and engineering skills to your team. You'll learn useful tricks, like how to write context managers and decorators. You'll also learn best practices around how to write maintainable reusable functions with good documentation. They say that people who can do good research and write high-quality code are unicorns. Take this course and discover the magic!

  1. 1

    Best Practices

    Free

    The goal of this course is to transform you into a Python expert, and so the first chapter starts off with best practices when writing functions. We'll cover docstrings and why they matter and how to know when you need to turn a chunk of code into a function. You will also learn the details of how Python passes arguments to functions, as well as some common gotchas that can cause debugging headaches when calling functions.

  2. Decorators

    Decorators are an extremely powerful concept in Python. They allow you to modify the behavior of a function without changing the code of the function itself. This chapter will lay the foundational concepts needed to thoroughly understand decorators (functions as objects, scope, and closures), and give you a good introduction into how decorators are used and defined. This deep dive into Python internals will set you up to be a superstar Pythonista.

  3. Context Managers

    If you've ever seen the "with" keyword in Python and wondered what its deal was, then this is the chapter for you! Context managers are a convenient way to provide connections in Python and guarantee that those connections get cleaned up when you are done using them. This chapter will show you how to use context managers, as well as how to write your own.

  4. More on Decorators

    Now that you understand how decorators work under the hood, this chapter gives you a bunch of real-world examples of when and how you would write decorators in your own code. You will also learn advanced decorator concepts like how to preserve the metadata of your decorated functions and how to write decorators that take arguments.

  1. 1

    Best Practices

    Free

    The goal of this course is to transform you into a Python expert, and so the first chapter starts off with best practices when writing functions. We'll cover docstrings and why they matter and how to know when you need to turn a chunk of code into a function. You will also learn the details of how Python passes arguments to functions, as well as some common gotchas that can cause debugging headaches when calling functions.

  2. Context Managers

    If you've ever seen the "with" keyword in Python and wondered what its deal was, then this is the chapter for you! Context managers are a convenient way to provide connections in Python and guarantee that those connections get cleaned up when you are done using them. This chapter will show you how to use context managers, as well as how to write your own.

  3. Decorators

    Decorators are an extremely powerful concept in Python. They allow you to modify the behavior of a function without changing the code of the function itself. This chapter will lay the foundational concepts needed to thoroughly understand decorators (functions as objects, scope, and closures), and give you a good introduction into how decorators are used and defined. This deep dive into Python internals will set you up to be a superstar Pythonista.

  4. More on Decorators

    Now that you understand how decorators work under the hood, this chapter gives you a bunch of real-world examples of when and how you would write decorators in your own code. You will also learn advanced decorator concepts like how to preserve the metadata of your decorated functions and how to write decorators that take arguments.

What do other learners have to say?

Devon

“I've used other sites, but DataCamp's been the one that I've stuck with.”

Devon Edwards Joseph

Lloyd's Banking Group

Louis

“DataCamp is the top resource I recommend for learning data science.”

Louis Maiden

Harvard Business School

Ronbowers

“DataCamp is by far my favorite website to learn from.”

Ronald Bowers

Decision Science Analytics @ USAA

Shayne Miel
Shayne Miel

Director of Software Engineering @ American Efficient

Shayne Miel has been building web-scale machine learning applications since 2006. Cycling between leadership roles (Tech Lead, Director, VP) and individual contributor roles at several large EdTech companies, he has honed his skills in both data science and engineering. These days you can find him at his standing desk architecting microservice solutions, training deep learning models, or building visualization tools to ensure his and his teammates' models are performing as desired. In the evenings he stops pretending to be a business professional and follows his true nature: playing board games and building pillow forts with his kids. Follow him on Twitter: @ShadyData

See More
Collaborators
  • Hillary Green-Lerman

    Hillary Green-Lerman

  • Becca Robins

    Becca Robins

Icon Icon Icon professional info