User Tools

Site Tools


python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python [2021/01/22 18:04] – [Convert strings to datetime] rogerpython [2023/01/01 18:43] (current) – external edit 127.0.0.1
Line 105: Line 105:
 print('yay!') if today == 'friday' else print('boo') print('yay!') if today == 'friday' else print('boo')
 >>> yay!  >>> yay! 
 +</code>
 +
 +==== Unpack extras on a tuple or list ====
 +
 +<code python>
 +t = (0, 1, 2, 3, 4)
 +
 +a, b, *c = t
 +
 +print(a)
 +print(b)
 +print(c)
 +# 0
 +# 1
 +# [2, 3, 4]
 +
 +print(type(c))
 +# <class 'list'>
 +
 +a, *b, c = t
 +
 +print(a)
 +print(b)
 +print(c)
 +# 0
 +# [1, 2, 3]
 +# 4
 +
 +*a, b, c = t
 +
 +print(a)
 +print(b)
 +print(c)
 +# [0, 1, 2]
 +# 3
 +# 4
 +
 </code> </code>
  
  
python.1611349496.txt.gz · Last modified: 2023/01/01 18:43 (external edit)