Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Examples of Python any parameters     - How to install the Linux text editor Atom 0.124.0 (Linux)

- PHP CURL get cookies simulated login (Database)

- Windows 7 hard disk installation notes Debian (Linux)

- OpenSUSE installation on CentOS6 (GUI) (Linux)

- How to Install Redis server on CentOS 7 (Server)

- Configuring Haproxy log support (syslog logging support) (Server)

- Linux tar compressed exclude a folder (Linux)

- The ActiveMQ JMS installation and application examples for Linux (Linux)

- Linux, MySQL root privilege escalation another method (Linux)

- To modify the existing user ID and comments GPG key (Linux)

- Java reflection technology explain (Programming)

- Linux how to view the graphics models notebook (Linux)

- CentOS 7 version how to achieve the power to start the graphical interface (Linux)

- Linux kernel netpoll framework netconsole (Linux)

- Thinking in Java study notes - Access modifiers (Programming)

- Restore database fault encountered ORA-0600 (Database)

- Ubuntu 14.04 Nvidia proprietary drivers for install two graphic cards (Linux)

- How to install and use the malware detection tool LMD and ClamAV antivirus engine on Linux (Linux)

- Beautiful start Ubuntu installation tool Duck Launcher 0.64.5 (Linux)

- Help you enhance Python programming languages 27 (Programming)

 
         
  Examples of Python any parameters
     
  Add Date : 2018-11-21      
         
         
         
  Collection parameters:

In the function definition, the collection of location parameters do not match the tuple.

>>> Def f (* args): print (args)

...

When this function is called, python relevant parameters for all positions collected into a new Ganso, and the assignment of this tuple to the variable args. (Can be indexed or stepping in for loop)

>>> F ()

()

>>> F (1)

(1,)

>>> F (1, 2, 3, 4)

(1, 2, 3, 4)

** Similar characteristics, but it is only valid for keyword arguments. These keyword arguments passed to the new dictionary.

>>> Def f (** args): print ((args)

...

>>> F ()

{}

>>> F (a = 1, b = 2)

{ 'A': 1, 'b': 2}

Another example:

>>> Def f (a, * pargs, ** kargs): print (a, pargs, kargs)

...

>>> F (1, 2, 3, x = 1, y = 2)

1 (2, 3) { 'y': 2, 'x': 1}

Unpack parameters

When you call the * syntax unpack parameter set.

>>> Def func (a, b, c, d): print (a, b, c, d)

...

>>> Args = (1, 2)

>>> Args + = (3, 4)

>>> Func (* args)

1234

Similarly, ** will be key-value pairs unpack a dictionary.

>>> Args = { 'a': 1, 'b': 2, 'c': 3}

>>> Args [ 'd'] = 4

>>> Func (** args)

1234

to sum up

* / ** Syntax: in the head, it means that any number of parameters were collected, and the call is unpack it any number of arguments.
     
         
         
         
  More:      
 
- Linux Network Security Tips Share (Linux)
- Oracle 11g maintenance partitions (eight) - Renaming Partitions (Database)
- Oracle background processes daemons (Database)
- Linux server remote user to obtain root privileges prevention (Linux)
- Oracle 11g partition maintenance (Nice) - Truncating And Partitions (Database)
- Using the Linux folder wc statistics number of lines of code for all files (including subdirectories) (Linux)
- RHEL5 / 6 Installation Notes (Linux)
- Execute command sentence can result in equipment permanently bricked in Linux laptop (Linux)
- Brief Linux commands (Linux)
- MySQL and Oracle time zone settings compare (Database)
- Two alert log ORA Errors (Database)
- Hibernate Search 5.5 in the search results sorted (Linux)
- SSL VPN SSL VPN access to security websites patron (Linux)
- Linux system security configuration (Linux)
- Oracle Database import and export combat (Database)
- Overall Physical Migration of Oracle Database with (Database)
- CentOS 5.3 under broadcom NIC dual activation issues (Linux)
- Why you can have JavaScript string method (Programming)
- SendMail version of Java implementation with attachments (Programming)
- Matters Oracle 11.2 single instance when connecting ASM need to pay attention and deal with the problem (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.