004--python ternary operations, Python functions

Source: Internet
Author: User

Ternary operations:

if + = = 2:p rint (True) Else:print (false) #等同于: print (True if 1+1==2 else False)

Basic syntax of the function Def XX ():

Define function # return AA return value # or pass nothing Returns # XX () Call function # The function has three different parameters: #------Normal parameter------def func (name): print (name) func (' Fanh Aibo ') #------Default parameters------def func2 (name,age=30):p rint (name,age) func2 (' Fanhaibo ') func2 (' Zhang San ', #) #------Dynamic Parameters------# * Argsdef func3 (*args):p rint (args) func3 (1) func3 (' Hello ') func3 (all in All) func3 ([]) func3 ({1: ' A ', 2: ' B '}) #**kwargs: Multiple elements can be passed in to key= valuedef Func4 (**kwargs):p rint (Kwargs) func4 (name= ' Fanhaibo ', age=30) #*args **kwargsdef Func5 (arg,* Args,**kwargs): #print (args) #print (Kwargs) print (Arg,args,kwargs) #把1传给arg, pass ' a ' B ' C ' as a tuple to args, name, Age passed to Kwargsfunc5 (1, ' A ', ' B ', ' C ', name= ' Fanhaibo ', age=30)


004--python ternary operations, Python 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.