Introduction to Python3 (4) - Python Functions

I. Overview

  Like other high-level languages, python supports functions

2. Function call

  Like other languages, write the function name and pass in the appropriate parameters, such as calling the built-in function abs:

>>> abs(-1)
1

  Functions support aliases:

>>> a = abs #The variable a points to the abs function 
>>> a(-1) #So you can also call the abs function 
1 through a

  If the wrong parameter is passed in, Python will report a TypeError error

  The conversion of data types in Python can be done through related functions:

>>> int('1')
1
>>> str(1)
'1'

3. Function Definition

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324779500&siteId=291194637