Tag:rtm coding ict owner allow csdn play model keyword argument
#!/usr/bin/python#-*-coding:utf-8-*-"1. Passing any number of arguments to Python allows the function to pass in any number of arguments, for example: * In the *messages parameter name means let Python create an empty tuple named messages, receiving all incoming values ' Def get_person_message (*messages): concat = ' for message in messages: Concat + = ' + message print ' \nshow person ' s message: ' + concat get_person_message (' CSDN ', ' http://blog.csdn.net/b inguo168 ') get_person_message (' http://www.cnblogs.com/binguo2008/') get_person_message (' Binguo ', ' + ', ' male ') get_ Person_message (' binguo168 ', ' ", ' male ', ' basketball ', ' Football ') ' 2. Use positional arguments and any number of arguments if the function needs to receive different types of positional arguments, You need to receive any number of arguments at the end. "Def set_computer_configure (cpu,memory,*others): concat = ' for info in Others:concat + = ' + info pri NT ' CPU: ' +cpu+ ' + Memory + ' Memory: ' + ' + ' others: ' +concatset_computer_configure (' Core i7 ', ' 32g ', ' Monitor:lg 27ud68 ' , ' Display card:geforce GTX 1060 ') set_computer_configure (' Intel Xeon e5-2679 ', ' 128g ', ' monitor:lg 27ud68 ') ' 3. Use any number of key arguments (receive any number of key-value pairs) through **arguname to receive any number of arguments, of which two * * indicates that the PYThon Create an empty dictionary, all incoming key-value pairs are placed in the dictionary "def Build_user_profile (username,**othersinfo): Dict_profile = {} dict_profile [' username '] = Username for userkey,uservalue in Othersinfo.items (): dict_profile[userkey] = Uservalue return Dict_profiletest_user_profile1 = build_user_profile (username = ' Binguo ', age = 27,gender = ' Male ') print test_user_prof Ile1test_user_profile2 = build_user_profile (username = ' binguo168 ', hobby = ' basketball ', blogs = ' CSDN ', Blog_url = ' http ://blog.csdn.net/binguo168 ') print Test_user_profile2 ' 4. Store the function in the module ' #导入整个模块import importmodelsysteminfo = im Portmodel.get_system_info (1) Print systeminfo# Import the specified function from Importmodel import get_system_info,get_system_ownerget_ System_info (1) get_system_owner () #使用as对模块设定别名import Importmodel as Testmodeltestmodel.get_system_info (1) # Import all functions in module from Importmodel import *get_system_info (1) get_system_owner ()
Python learning Experience (c) any number of arguments to the function, any number of keyword arguments, functions in the Import module