1
0

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 3 years have passed since last update.

1桁の数字をゼロを埋めて”01”や”02”など2桁にしてソートしやすくする方法

1
Last updated at Posted at 2022-12-13

1桁の数字をゼロを埋めて”01”や”02”など2桁にしてソートしやすくする方法

f'と{i}を使ってfor文で回してファイル名を動的に変更する

1桁

f'target{i+1}.png') #1桁:target5.png

3桁

f'target{str(i+1).zfill(3)}.png') # 3桁:target005.png

zfill(2)の2は桁数を表しています。この場合1-9が01-09になります。

str(index+1).zfill(2)

1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?