計算機科学のブログ

ほしい物リスト

Python - Diving in: Let's Make a Splash - multiple assignment, unpacking 1

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 2.(Diving in: Let’s Make a Splash)、SHARPEN YOUR PENCIL(147/682)の解答を求めてみる。

Jupyter(コード、入出力結果)

Darius.ipynb

swimmer, age, distance, stroke = fn.removesuffix('.txt').split('-')
print(swimmer)
print(age)
print(distance)
print(stroke)
Darius
13
100m
Fly
fn = 'Abi-10-5lm-Back.txt'
swimmer, age, distance, stroke = fn.removesuffix('.txt').split('-')
print(swimmer)
print(age)
print(distance)
print(stroke)
Abi
10
5lm
Back