How to use the asterisk (*) in Python. Maybe this is all? ..

Overview

I didn't understand how to use the asterisk (*) in Python (3.7 I'm using now), so I looked it up.

https://docs.python.org/ja/3.7/reference/

image.png

image.png

image.png

image.png

The point was to show where it was explained in the reference. Also, the asterisk in the argument of the function is famous, but I felt that I wanted to show (I want to) that the argument alone does not have any special usage. All citations are result usage 1 (multiplication operation) usage 2 (exponentiation operation) usage 3 (unpacking of argument list)

image.png

How to use 4 (Unpack the dictionary)

image.png

image.png

Example ↓. This is unlikely to be used much.

>>>
>>> ff = {'a':1,'b':2}
>>> gg = {**ff,'c':3}
>>> gg
{'a': 1, 'b': 2, 'c': 3}
>>>

How to use 5 (Unpacked Iterable)

image.png

image.png

Example ↓. This may be used. However, it is not appropriate as an example in this section. Is this an argument system, if anything? ??

>>>
>>> (hh,*ii)=1,2,3,4,5,6
>>> ii
[2, 3, 4, 5, 6]
>>>

I think the example below is appropriate.

>>>
>>> ii=[1,2,3]
>>> jj=[100,200,*ii]
>>> jj
[100, 200, 1, 2, 3]
>>> jj=[100,200,ii]
>>> jj
[100, 200, [1, 2, 3]]
>>>

Summary

Nothing in particular. If you have any comments, please let us know. : candy:

Recommended Posts

How to use the asterisk (*) in Python. Maybe this is all? ..
How to use is and == in Python
How to use the C library in Python
How to use the model learned in Lobe in Python
How to use SQLite in Python
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
How to use the __call__ method in a Python class
How to use __slots__ in Python class
How to use regular expressions in Python
How to judge that the cross key is input in Python3
[Introduction to Python] How to use the in operator in a for statement?
(Maybe) This is all you need to pass the Python 3 Engineer Certification Data Analysis Exam
How to use Python Image Library in python3 series
Summary of how to use MNIST in Python
[Algorithm x Python] How to use the list
How to get the files in the [Python] folder
How to use tkinter with python in pyenv
How to retrieve the nth largest value in Python
[For beginners] How to use say command in python!
How to get the variable name itself in python
How to get the number of digits in Python
python3: How to use bottle (2)
How to use the generator
How to know the current directory in Python in Blender
Tips for those who are wondering how to use is and == in Python
[Python] How to use list 1
How to read all the classes contained in * .py in the directory specified by Python
How to use the Raspberry Pi relay module Python
How to use Python argparse
[Python] How to use the graph creation library Altair
How to use the exists clause in Django's queryset
Python: How to use pydub
[Python] How to use checkio
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
I tried to summarize how to use pandas in python
[Introduction to Udemy Python3 + Application] 30. How to use the set
How to develop in Python
[Python] How to output the list values in order
[Python] How to use input ()
How to use the decorator
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
I want to use the R dataset in python
python3: How to use bottle
How to use Python bytes
How to check in Python if one of the elements of a list is in another list
How to test that Exception is raised in python unittest
[python] How to check if the Key exists in the dictionary
How to debug the Python standard library in Visual Studio
[python] How to use the library Matplotlib for drawing graphs
[Hyperledger Iroha] Notes on how to use the Python SDK
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
Comparison of how to use higher-order functions in Python 2 and 3
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
I didn't know how to use the [python] for statement
Notes on how to use marshmallow in the schema library
[Python] How to do PCA in Python