Python Learning Note (ix)-function 2

Source: Internet
Author: User

Exchange values for two variables

A = 2= 1= 1 A = 2# Way One:# swap values for two variables print(A, b)  # Way two:a = a + b  #3b = a  #2a = A-  #3-2

#列表推导式

Nums = [0,1,3,4,5,6,7 for in nums]print(new_nums)

Return multiple values

If the function has more than one return value, the values of the return will be placed in a tuple and returned

def Hello (a,b,c,d):    return  = Hello ('ybq','mpp','zhx ','lby')print(res)

function is variable

defAdd ():Print('Add Item')defview ():Print('View Products')defDelete ():Print('Delete Item') Choice= Input ('Please enter select 1, 2, 3,'). Strip () menu= {    '1': Add,'2': View,'3':d elete}ifChoiceinchMenu:menu[choice] ()#suitable for functions that have no arguments, or where the parameters are the same. Else:    Print('Input Error')

Built-in functions

#len type print input strPrint(All ([1, 2, 3, 4]))#determine if the values in an iterative object are truePrint(Any ([0, 1, 2, 3, 4]))#determines whether the value inside an object that can be iterated has a truePrint(Bin (100))#Decimal Turn binaryEjz = Bin (100)Print(Ejz.replace ('0b',"'))#Binary is the beginning of the 0b, using the replacement to remove the 0bPrint(Chr (65))#print the ASCII corresponding to the numberPrint(Ord ('A'))#Print the ASCII code corresponding to the stringPrint(dir (1))#to print a callable method of an incoming objectPrint(Filter (Lambdax:x > 5, [12, 3, 12, 2, 1, 2, 35])#Filter The following iteration objects according to the previous methodPrint(Map (Lambdax:x > 5, [1, 2, 3, 4, 5, 6])#print them all according to the expression#Zipids= [1,2,3,4,7,8,0,-1]names=['Little Black','Small white','Xiao Huang','Little Green']names1=['Little Black','Small white','Xiao Huang','Little Green'] forId,name,sinchZip (ids,names,names1):Print(id,name,s)Print(Sorted ('0123450'))#AscendingPrint(Sorted (ids,reverse=true))#DescendingRound (1.987123,5)#Keep several decimals

Python learning Note (ix)-function 2

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.