In-depth answers to 11 Python Foundation questions

Source: Internet
Author: User

1. Whether the parameter passing of Python is a value pass or a

Illustrate several forms of Python function parameter passing, and indicate whether a function argument is a value pass or a reference pass

First, Position parameters

The function is called when the parameter is passed according to the parameter position defined by the function. Example:

def print_hello (name, sex):
Sex_dict = {1:u ' Mr. ', 2:u ' lady '}
Print (' Hello%s '%s, welcome to Python world! '% (name, sex_dict.get (Sex, Mr. U ')))


# Two The order of the parameters must be one by one corresponding, and one less parameter can not
Print_hello (' Tanggu ', 2) #输出: Hello Tanggu, welcome to Python world!
Print_hello (' Tanggu ', 3) #输出: Hello Tanggu, Welcome to Python world! (the dictionary does not have a value of 3, so return "Sir")



# get () usage in dictionary: Dict.get (Key, Default=none)
#key-the key to find in the dictionary. Default-Returns the default value if the value of the specified key does not exist.

In-depth answers to 11 Python Foundation questions

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.