What are Functions?
Functions are simply pre-written codes that perform a certain task. For an analogy, think of the mathematical functions available in MS Excel. To add numbers, we can use the sum() function and type sum(A1:A5) instead of typing A1+A2+A3+A4+A5.
函数是预先写好的代码,用于执行某项任务。做个类比,在MS Excel中,我们使用sum()函数可以把数字相加。
Depending on how the function is written, whether it is part of a class (a class is a concept in object-oriented programming) and how you import it, we can call a function simply by typing the name of the function or by using the dot notation. Some functions require us to pass data in for them to perform their tasks. These data are known as parameters and we pass them to the function by enclosing their values in parenthesis ( ) separated by commas.
取决于这个函数是否为类的一部分以及调用方式,我们可以通过如下方式使用一个函数:函数名加圆括号,圆括号中传入参数,如果多个参数,用逗号隔开。
For instance, to use the print() function for displaying text on the screen, we call it by typing print(“Hello World”) where print is the name of the function and “Hello World”is the parameter.
举个栗子,print函数,print(“Hello World”),print是函数名,Hello World是参数。