Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Python function arguments * args and ** kwargs usage     - Linux Mint brightness adjustment --xrandr command learning (Linux)

- Ubuntu Tutorial: How to Upgrade a New Linux Kernel 3.12.7 on Ubuntu (Linux)

- CentOS6.3 build a Python 3.3 environment to access Oracle 11gR2 (Database)

- Debian 7 and Debian 8 users how to install Oracle Java 8 (Linux)

- C language macro definition #define Usage (Programming)

- 8 Git tips (Linux)

- Linux set the maximum number of open files nofile and nr_open, file-max Description (Linux)

- Firewall types and instructions (Linux)

- The virtual memory (Linux)

- Linux_Logo - output color ANSI Linux distributions logo command-line tool (Linux)

- Shell array: Define Shell array, the array length (Programming)

- PHP 7.0 Upgrade Notes (Linux)

- Manually create Oracle Database Explanations (Database)

- ogg Oracle to SQL Server 2005 to achieve synchronization (Database)

- Use LKM change the default linux security level (Linux)

- Timeout control related to Python threads and a simple application (Programming)

- Git uses a small mind (Linux)

- Use CutyCapt to convert HTML pages to png images on Linux (Linux)

- FPM quickly create packages with RPM (Linux)

- Replace font under Linux (Linux)

 
         
  Python function arguments * args and ** kwargs usage
     
  Add Date : 2018-11-21      
         
         
         
  Args is an array of all parameters, kwargs is that when you pass key = value is stored in the dictionary, when the function parameter uncertainty, you can use the * args and kwargs, * args no key value, kwargs have key value

    def fun_var_args (farg, * args):
        print "arg:", farg
        for value in args:
            print "another arg:", value
      
    fun_var_args (1, "two", 3) # * args can accommodate multiple variables can be used as component list

result:

arg: 1
another arg: two
another arg: 3

** Kwargs:

    def fun_var_kwargs (farg, ** kwargs):
        print "arg:", farg
        for key in kwargs:
            print "another keyword arg:% s:% s"% (key, kwargs [key])
      
    fun_var_kwargs (farg = 1, myarg2 = "two", myarg3 = 3) # myarg2 and myarg3 is considered key, feel ** kwargs can accommodate a plurality of key and value as the dictionary


result:

    arg: 1
    another keyword arg: myarg2: two
    another keyword arg: myarg3: 3

You can also use the following form:

def fun_var_args_call (arg1, arg2, arg3):
    print "arg1:", arg1
    print "arg2:", arg2
    print "arg3:", arg3
  
args = [ "two", 3] #list
  
fun_var_args_call (1, * args)

result:

    arg1: 1
    arg2: two
    arg3: 3

    def fun_var_args_call (arg1, arg2, arg3):
        print "arg1:", arg1
        print "arg2:", arg2
        print "arg3:", arg3
      
    kwargs = { "arg3": 3, "arg2": "two"} # dictionary
      
    fun_var_args_call (1, ** kwargs)

result:

    arg1: 1
    arg2: "two"
    arg3: 3

When all the Senate as key = value form will return a dictionary
     
         
         
         
  More:      
 
- innodb storage engine backup tool --Xtrabackup (Database)
- Linux Defensive / mitigate DDOS attacks (Linux)
- CentOS 6.5 platform offline compile and install PHP5.6.6 (Server)
- Python decorators to learn and practice the actual usage scenarios (Programming)
- The best known for archiving / compression tool under linux (Linux)
- How to configure SNMPv3 on Ubuntu, CentOS and Cisco systems (Linux)
- Changes in C # asynchronous programming model (Programming)
- Oracle 11gr2 new APPEND_VALUES tips (Database)
- Open container cluster management system architecture and components introduced Kubernetes (Server)
- Python Socket Network Programming (Programming)
- How to protect your eyes automatically adjust the screen brightness on Linux (Linux)
- Mount NFS network file system (Linux)
- CentOS 7 Test Marathon start Docker container (Server)
- Shell Script: create a function and specify a directory for download (Programming)
- IntelliJ IDEA run in Mac10.9 and JDK7 environment (Linux)
- GDB remote connections RX Probe online debug program (Programming)
- To build a private Docker registry (Server)
- Oracle inline view updates problems encountered (Database)
- Easily solve the MySQL database connection error too many (Database)
- Oracle PLS-00231 error analysis (Database)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.