計算機科学のブログ

ほしい物リスト

Python - Diving in: Let's Make a Splash - string, split method 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(138/682)の解答を求めてみる。

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

Darius.ipynb

fn = 'Darius-13-100m-Fly.txt'
fn.split("13") == ['Darius-', '-100m-Fly.txt']
True
fn.split('-1') == ['Darius', '3', '00m-Fly.txt']
True
fn.split('.') == ['Darius-13-100m-Fly', 'txt']
True
fn.split('-.') == ['Darius-13-100m-Fly.txt']
True
fn.split('-').split('.')
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

Cell In[9], line 1
----> 1 fn.split('-').split('.')


AttributeError: 'list' object has no attribute 'split'