Python - Diving in: Let's Make a Splash - string, split method
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter2.(Diving in: Let’s Make a Splash)、SHARPEN YOUR PENCIL(44/82)の解答を求めてみる。
Jupyter(コード、入出力結果)
Drius.ipynb
fn = 'Darious-13-100m-Fly.txt'
fn.split('13') # ['Darious-','100m-Fly.txt']
['Darious-', '-100m-Fly.txt']
fn.split('-1') # ['Darious', '3', '00m-Fly.txt']
['Darious', '3', '00m-Fly.txt']
fn.split('.') # ['Darious-13-100m-Fly', 'txt']
['Darious-13-100m-Fly', 'txt']
fn.split('-.') # ['Darious-13-100m-Fly.txt']
['Darious-13-100m-Fly.txt']
fn.split('-').split('.') # exception
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 1
----> 1 fn.split('-').split('.') # exception
AttributeError: 'list' object has no attribute 'split'