LimioLearn in Flow
🏆 Đấu trường
Đăng nhậpĐăng ký
← Programming for Data Science

Bạn đang xem thử công khai

Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.

Đăng nhập
Module 1: Fundamentals of Python Programming

1.9 Functions

In / Lưu PDF

1.9 Functions

After this unit you will: package a task into a reusable function and understand where variables live.

Key points

  • A parameter is the name in the definition; an argument is the value passed at call time.
  • Default parameter: def power(base, exp=2).
  • *args collects extra positional arguments into a tuple; **kwargs collects keyword arguments into a dict.
  • lambda x: x ** 2 is a one-line anonymous function.
  • Assigning inside a function creates a new local variable; to change an outer variable you must declare it global.