Built-in functions

Source: Internet
Author: User
Tags vars

Function Classification:

Built-in functions
System-defined methods
Custom functions
A block of code that a developer writes to complete a function
Import module (third-party module)
A block of code that can be implemented by someone other than the system and the developer to implement a function

Sample script:

Vim built-in function.py

#!/usr/bin/env python
#-*-Coding:utf-8-*-
"""
This script is a test script for Python built-in functions
"""
Li = [13,22,6,99,11]
name = ' Alex '
Print VARs ()

#vars () is all variables that represent the current module, and print VARs () prints all the variables

Output Result:
{' name ': ' Alex ', ' __builtins__ ': <module ' __builtin__ ' (built-in);, ' __file__ ': ' c:/users/ryan/pycharmprojects/ S11day3/built-in function.py ', ' __author__ ': ' Ryan ', ' Li ': [6], ' __name__ ': ' __main__ ', ' __package__ ': Non E, ' __doc__ ': None}
From the diagram you can see that the output is a dictionary:
Name:alex
Li: [13, 22, 6, 99, 11]
is our own definition of the two variables, the following functions are built-in functions of the system, the specific functions are as follows
__builtins__:<module ' __builtin__ ' (built-in) >
__file__:c:/users/ryan/pycharmprojects/s11day3/built-in function.py
__author__:ryan

__name__:__main__
__package__:none
__DOC__: None

From the dictionary key-value pairs can be found,

The built-in function __file__ is actually a print run script itself, that is built-in function.py
The built-in function __doc__ is the content that gets the function or the file to interpret, for example, we start writing the comment on the file
"""
This script is a test script for Python built-in functions
"""
When you print __doc__, you can print it through the __doc__ function


C:/users/ryan/pycharmprojects/s11day3/built-in function.py

This script is a test script for Python built-in functions


built-in functions: __name__ when executing scripts. The value of __name__ in the script is "__main__", the module is imported into the script, the value of __name__ in the module is the module itself

Or take the script above as an example:

Import Coll
Print coll.__name__
Print "###############"
Print __name__


The output is:

Coll
###############
__main__

You can see that the value of the __name__ built-in method in Coll is equal to __name__ in Coll,built-in function.py

equals __main__

That is, the __name__ method value in the Import module is the module name, and the value of the __name__ method in the executed script is __main__


When writing a Python script, the following statement usually appears at the end:

If __name = "__main__":

Functional function ()


This means that the function is called when the script is executed directly, and if other methods are executed (or imported into other files), the function function () is not executed.


Common functions (methods):

#基础类型级别
Help ()
Dir ()
VARs ()
Type ()
Reload ()
ID ()
Is

#计算类别的
CMP ()
ABS ()
BOOL ()
Divmod ()---> design page paging Use this function to find out quotient and remainder, and to determine whether N is added
Max ()
Min ()
SUM ()
POW ()---> Power operation

##################
Len ()---> Sequence length
All ()---> Receive a sequence, judging if the value is true, then all () returns True, otherwise false, can be used to determine whether the user input is empty
Any ()---> Similar to All (), the difference is that as long as one of the received content is true, it returns true, otherwise false

#编码转换
Chr ()-----> receives a character, which is a numeric representation of the character in ASCII code based on the character
Ord ()-----> receives a number to figure out the letter that the number represents in the ASCII code

#进制转换
Hex ()-----> Hex
Oct ()-----> Octal
Bin ()------> Binary
>>> Hex (12)
' 0xc '
>>> Oct (12)
' 014 '
>>> Bin (12)
' 0b1100 '
>>>

Enumerate ()-------> The incoming list can be made into a dictionary

>>> li = [11,22,33,44,55,66]
>>> for K,v in Enumerate (LI):
... print K,v
...
0 11
1 22
2 33
3 44
4 55
5 66
>>>

Specify the starting value of the number, without 1, starting from 0 by default

>>> for K,v in Enumerate (li,1):
... print K,v
...
1 11
2 22
3 33
4 44
5 55
6 66
>>>


Common function-related methods:

Print Apply (Function, (' aaaa ')) #执行函数
Print map (lambda x:x+1,[1,2,3,]) #all
Print fileter (lambda x:x==1,[1,2,3,4]) #True sequence
Print reduce (lambda x,y:x+y,[1,2,3]) #累加
Print zip (x, y, z)





This article from "Flat Light is true" blog, please be sure to keep this source http://cryan.blog.51cto.com/10837891/1717648

Built-in functions

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.