Python notes 2

Source: Internet
Author: User

Reference text:

Http://www.liaoxuefeng.com

1. Functions
(1) Python's commonly used built-in functions:
A. Absolute value return function: ABS (x)
B. Comparison function: cmp (x, y)
C. Data type conversion function: Int (), float (), str ()
(2) Assigning a function name to a variable, you can call the function by the variable name.
(3) Defining functions
A. Define a function to use the DEF statement, write down the function name, parentheses, the arguments in parentheses, and the colon: and then, in the indent block, write the function body, and the return value of the function is returned with a return statement.
B.python's built-in functions have parameter checks, and custom functions need to add their own parameter checks, which are added in the Indent module first
If not isinstance (x, (int, float)):
Raise TypeError (' bad operand type ')
Parameters that represent functions are only integral and floating-point.
(4) NULL function
Application of Pass
(5) If you need to return a value, the function returns a tuple

Python notes 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.