Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Examples of Python any parameters     - Java data structures - the single linked list LinkedList linear table (Programming)

- numpy and SciPy installation under Python for scientific computing package (Linux)

- File easier to compare tools under Linux (Linux)

- Service Discovery: Zookeeper vs etcd vs Consul (Server)

- C language - Traverse pci device (Programming)

- C / C ++ language usage summary of const (Programming)

- Linux file permissions to modify the command: chmod (Linux)

- Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster (Server)

- Vim plugin installation YouCompleteMe (Linux)

- CentOS 6.6 installation certification system based on the ftp service (Server)

- C ++ in the elimination Wunused (Programming)

- Linux System Getting Started Learning: Linux how to install 7zip (Linux)

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

- SUSE Linux install Oracle 10g and problem solving (Linux)

- Use MD5 transform algorithm to prevent exhaustive decipher passwords (Linux)

- Qt for file splitting and fusion gadgets (Programming)

- Dom4j change XML coding (Programming)

- Several configuration changes illustrate deployment of PHP (Server)

- On FreeBSD 10.2 Bugzilla how to install and configure Apache SSL (Server)

- WEB-based Android Remote Tools Python implementation (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:      
 
- How x2go set up Remote Desktop on Linux (Linux)
- User and user group management Linux Command (Linux)
- MySQL can not write the data keyword conflicts (Database)
- Zabbix monitors the status of TCP connections (Server)
- When Vim create Python scripts, vim autocomplete interpreter and encoding method (Programming)
- Build your own Python coding environment (Linux)
- MySQL use the integer type (Database)
- Ubuntu 14.04 kernel after the restart boot black screen to solve (Linux)
- Why JavaScript basic types can invoke methods (Programming)
- How to monitor Linux system performance Nmon (Linux)
- Mac Docker deploy development environment (Server)
- Linux LVM Logical Volume Management to resize partitions (Linux)
- Lazarus IDE Start Basics Tutorial (Linux)
- C ++ virtual functions Classic Insights (Programming)
- Why you can have JavaScript string method (Programming)
- Safe learning through self-extracting package to achieve invasion (Linux)
- What factors affect the performance of Java calls (Programming)
- Each catalog Detailed Linux (Linux)
- The callback function used in C ++ (Programming)
- Oracle archive log deletion (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.