rogs wiki

my wiki, quick and useful snippets of code

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
python [2021/01/22 18:04] – [Convert strings to datetime] rogerpython [2021/02/05 13:31] (current) 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.1611349496.txt.gz · Last modified: 2021/01/22 18:04 by roger