Python - Diving in: Let's Make a Splash - multiple assignment, unpacking
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter 2.(Diving in: Let’s Make a Splash)、SHARPEN YOUR PENCIL(147/682)の解答を求めてみる。
Jupyter(コード、入出力結果)
Darius.ipynb
fn = 'Darius-13-100m-Fly.txt'
swimmer, age, distance, stroke = fn.removesuffix('.txt').split('-')
print(swimmer, age, distance, stroke, sep='\n')
Darius
13
100m
Fly
fn = 'Abi-10-50m-Back.txt'
swimmer, age, distance, stroke = fn.removesuffix('.txt').split('-')
print(swimmer, age, distance, stroke, sep='\n')
Abi
10
50m
Back