Python_python built-in functions

Source: Internet
Author: User
Tags decimal to binary

# One, less use of global variables
# 1. Unsafe, easy to modify
# 2. Running with in-occupied memory
# Two, the function returns multiple values, if more than one value is returned, the result of return is returned in tuple format

# Three, List derivation
Res= Hello (' Ybq ',' MPP ',' Zhx ',' Lby ')
Print (RES)
Nums= [0,1,3,4,5,6,7]
New_nums= [x-1For XIn Nums]
Print (new_nums)
# 四、一个 function only implements one function, the less code the better
# Five, constant
# A constant is a variable that does not change.
# constant names are all defined in uppercase letters.

# variable Exchange
A = 2
b = 1
# b = 1 A = 2
# b,a = A, b #交换两个变量的值
# print (A, B)
A = a + b # 3
b = a -b # 2
A = a -b # 3-2

# built-in functions
# function is variable
# len type print input str

PrintAll ([1,2,3,4]))# Determine if the values inside an iterative object are true
PrintAny ([0,1,2,3,4]))# Determine if there is a true value in an object that can be iterated
PrintBin100))# Decimal to binary binary
Print (Ejz.replace (' 0b ',‘‘))# 0b characters added by default after de-binary
PrintChr65))# Print the ASCII corresponding to the number
PrintOrd' A '))# Print the ASCII code corresponding to the string
PrintDir1))# To print callable methods of incoming objects
PrintEval‘[]‘))# Execute Python code, only perform simple, define data types and operations
Code=' Def a ():p rint (' AA ') '
PrintEXEC (code))# Execute Python code
PrintSorted' 0123450 '))# Ascending
Ids= [1,2,3,4,7,8,0,-1]
PrintSorted (IDs,Reverse=true))# Descending
Round1.987123,5)# Keep a few decimals

Names= [' Little Black ',' Little White ',' Little Yellow ',' Little Green ']
Names1= [' Little Black ',' Little White ',' Little Yellow ',' Little Green ']
# Zip loop fetch number
For ID, name, sInchZip (IDs, names, names1):# cycle through several, whichever is less
Print (ID, name, s)

# Filter Loop Call function, filter only save results return True
DefFuncA:# 0 1 2
Return True
Return False

Nums= [xFor XInchRange11)]
Res=Filter (func, Nums)
PrintList (res))

# The map loop calls the function and returns the result of each call to the function in a list
All_res= []
For NumIn Nums:
Res= func (num)
All_res.append (RES)
Res=Map (func, Nums)
PrintList (res))

# function is variable
DefAdd ():
Print' Add Item ')

DefView ():
Print' View Products ')

DefDelete ():
Print' Delete Items ')

Choice=Input' Please enter select 1, 2, 3, '). Strip ()

Menu= {
' 1 ' : Add, # directly through the variable call function
' 2 ' : View,
' 3 ' : Delete
if choice in menu:
Span style= "Font-weight:bold" > Menu[choice] () # suitable for functions without arguments, Or the parameter is the same as the case.
Print (

Python_python 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: 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.