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
Last revisionBoth sides next revision
python [2021/01/22 18:04] – [Convert strings to datetime] rogerpython [2021/02/05 13:31] roger
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.txt · Last modified: 2023/01/01 18:43 by 127.0.0.1