跳至内容
首页Python

课程

Python 函数编写

中级技能水平
更新时间 2025年11月
学习使用最佳实践编写可维护、可复用、复杂且文档完善的函数。
免费开始课程
PythonProgramming
4小时
15 视频
46 道练习
3,650 XP
110K+
成就证明

创建您的免费帐户

继续使用 Google显示更多选项


继续操作即表示您接受我们的《使用条款》和《隐私政策》,并同意您的数据存储在美国。

深受数千家公司学习者的喜爱

Group

需要团队培训?

企业版试用

课程描述

您已经完成了分析、撰写了报告、训练好了模型。接下来呢?如果要将模型部署到生产环境,代码需要比在 Jupyter notebook 中的探索性脚本更可靠。通过本课程"Python 函数编写",您将夯实编写复杂而优雅函数的基础,从而为团队贡献研究与工程能力。您会学习实用技巧,例如如何编写上下文管理器和装饰器。您还将掌握可维护、可复用且文档完善的函数编写最佳实践。人们常说,既能做好研究又能写高质量代码的人是"独角兽"。参加本课程,亲自体验其中的妙处吧!

先决条件

Python Toolbox
1

Best Practices

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. You'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.
开始章节
Python 函数编写
课程完成

获得成就证明

将此证书添加到您的 LinkedIn 档案、简历或履历中
在社交媒体和绩效评估中分享
立即注册

加入超过19百万学习者,今天就开始Python 函数编写!

创建您的免费帐户

继续使用 Google显示更多选项


继续操作即表示您接受我们的《使用条款》和《隐私政策》,并同意您的数据存储在美国。

通过 DataCamp for Mobile 提升您的数据技能

随时随地通过我们的移动课程和每日 5 分钟编程挑战提升技能。