GO TO reference
- (*): 곱셈 연산자 (mulitplication)
- (**):지수화 연산자 (exponentiation)
In [1]: 2 * 5
Out[1]: 10
In [2]: 2 ** 5
Out[2]: 32
- (*) asterisk unpack iterables into a LIST
- (**) asterisk unpack iterables into a TUPLE
In [1]: numbers = [1,2,3,4]
In [2]: more_numbers = [numbers,5,6,7]
In [3]: print(more_numbers)
[[1, 2, 3, 4], 5, 6, 7]
In [4]: more_numbers = [*numbers,5,6,7]
In [5]: print(*more_numbers)
1 2 3 4 5 6 7
In [6]: print(*more_numbers,sep=',')
1,2,3,4,5,6,7
In [4]: more_numbers = [*numbers,5,6,7]
In [5]: print(*more_numbers)
1 2 3 4 5 6 7
In [6]: *more_numbers
File "<ipython-input-6-ca6965ea3cdc>", line 4
SyntaxError: can't use starred expression here
In [7]: print(*more_numbers,sep=',')
1,2,3,4,5,6,7
In [2]: points = [[1,2],[3,4],[5,6]]
In [3]: print(row for row in zip(*points))
<generator object <genexpr> at 0x7fe914277830>
In [4]: print([row for row in zip(*points)])
[(1, 3, 5), (2, 4, 6)]
<generator object at 0x7fe914277830> (warning)
(SOLUTION) tuple() or list() to convert that generator expression
In [1]: fruits = ['lemon','pear','watermelon','tomato']
In [2]: numbers = [1,2,3,4]
In [3]: print(*fruits, *numbers)
lemon pear watermelon tomato 1 2 3 4
In [4]: print(*fruits, *numbers,sep=',')
lemon,pear,watermelon,tomato,1,2,3,4
In [1]: date_info= {'year':2020, 'month': 1, 'day': 1}
In [2]: track_info = {'artist':'Beethoven','title':'symphony no.5'}
In [3]: file_name = "{year}-{month}-{day}, artist-{artist}, title-{title}".format(** date_info, **track_info)
In [4]: print(file_name)
2020-1-1, artist-Beethoven, title-symphony no.5