2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python split関数の使い方

Last updated at Posted at 2018-05-28

Python split関数の使い方備忘録

Pythonのsplit関数を使って便利であったため,備忘録として残しておこうと思う.
初めて投稿するため,拙い文章で恥ずかしいが少しずつ成長したいと思う.
今回の目標はカレントディレクトリの'date'の部分を取り出したい.

current_directry = 'User/name/Desctop/folder/date'

カレントディレクトリを'/'で区切る.

x = current_directry.split('/')

対話型でみるとこうなる.

In [1]: x
Out[1]: ['User', 'name', 'Desctop', 'folder', 'date']

この状態で,date部分を取り出したいため,以下のようにするとdateが取り出せる.

In [33]: x=l.split('/')[-1]

In [34]: x
Out[34]: 'date'
2
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?