Introduction to Python ternary operations and Python functions

Source: Internet
Author: User
This article introduces three-way Python operations and three-way Python functions:

If 1 + 1 = 2: print (True) else: print (False) # Equivalent to: print (True if 1 + 1 = 2 else False)

Function basic syntax def XX ():

Define the function # return aa return value # or pass does not return anything # XX () call the function # The function has three different parameters: # ------ common parameter ------ def func (name ): print (name) func ('fanhaibo ') # ------ default parameter ------ def func2 (name, age = 30): print (name, age) func2 ('fanhaibo ') func2 ('Zhang San', 20) # ------ dynamic parameter ------ # * argsdef func3 (* args): print (args) func3 (1) func3 ('Hello') func3 (1, 2, 3) func3 ([1, 2, 3]) func3 ({1: 'A', 2: 'B'}) # ** kwargs: multiple elements can be input with key = valuedef func4 (** kwargs): print (kwargs) func4 (name = 'fanhaibo', age = 30) # * args ** kwargs def func5 (arg, * args, ** kwargs): # print (args) # print (kwargs) print (arg, args, kwargs) # pass 1 to arg, send 'A' B 'C' as a tuples to args, and pass name and age to kwargsfunc5 (1, 'A',' B ', 'C', name = 'fanhaibo ', age = 30)

The above is a detailed introduction to Python trielement operations and Python functions. For more information, see other related articles in the first PHP community!

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.