Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 80

Python Insight

Оглавление

Python methods and functions are similar yet have an important distinction. As we saw in Chapter 2, functions are subroutines of code that perform a specific task and can return a value. We also can create our own functions to better organize code and enable code reusability. To use a function in Python code, we specify the function name along with any arguments that it might use. Methods also perform a specific task and can return a value, but the important distinction is that methods are directly associated with an object. To use a method, we specify the object and use the dot operator to specify which method to use. We can also create new object types along with methods and properties. Please see The Python Language Reference (Python Software Foundation, 2019, “The Python Language Reference”) for a detailed explanation of the process.

Introduction to Python Programming for Business and Social Science Applications

Подняться наверх