Python Learning note __2.1 Call function

Source: Internet
Author: User
Tags abs

# This is a learning note for the Liaoche teacher Python tutorial


Functions are the most basic form of code abstraction. Python is not only very flexible in defining functions, but it has built in many useful functions that can be called directly.


1. Calling Python intrinsics

Python has built in a lot of useful functions that we can call directly.

To invoke a function, you need to know the name and parameters of the function, such as the function abs with absolute value, only one parameter

Call the ABS function:

>>>abs (100)

100

>>>abs (-20)

20

>>>abs (12.34)

12.34

Note: When calling a function, if the incoming parameter number and parameter type are incorrect, an error will be

Call the Max function:

>>>max (1, 2)

2

>>>max (2, 3, 1,-5)

3

Data type conversion functions (int, float, str, BOOL)

>>>int (' 123 ')

123

>>>int (12.34)

12

>>>float (' 12.34 ')

12.34

>>>STR (1.23)

' 1.23 '

>>>STR (100)

' 100 '

>>>bool (1)

True

>>>bool (")

False

The nature of the function name:

The function name is actually a reference to a function object, assigning the function name to a variable, which is equivalent to giving the function an "alias".

>>>A = ABS # variable a points to ABS function

>>>a (-1) # So you can also call the ABS function by a

1

2. Examples

Use the Python built-in hex () function to convert an integer to a hexadecimal-represented string

#-*-Coding:utf-8-*-

N1 = 255

N2 = 1000

Print (Hex (N1))

Print (Hex (n2))

3. Reference documents

Built-in functions in Python (https://docs.python.org/3/library/functions.html)

Python Learning note __2.1 Call function

Related Article

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.