0
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 リストの中の数字を文字列に変換する方法

Posted at

こんな感じで、リストの中にINTEGERの要素があり、文字列に変換したい時がある。

sample.py
user_list = [1, 2, 3]

その場合はmapメソッドを使うと簡単に変換できる

sample.py
user_list_str = list(map(str,user_list))

出力結果

sample.py
user_list = [1, 2, 3]
user_list_str = list(map(str,user_list))
print(user_list_str)

# 出力結果
['1', '2', '3']

反対に文字列から数値にしたい場合はstrの部分をintにすればok

0
3
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
0
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?