LoginSignup
26
19

More than 5 years have passed since last update.

数値が入ったリストの文字列変換

Posted at

各要素の文字列への変換

リストに数値がいくつか入っているとき、それらを全て文字列に変換するにはmapを使う。

>>>list = [0,1,2,3,4,5]
>>>map(str,list)
['0', '1', '2', '3', '4', '5']

また、これらの要素を","などで区切って一つの文字列にしたい時も一行で書ける。

>>>','.join(map(str,list))
'0,1,2,3,4,5'

センサなどで計測したデータを送信したりするときに便利。

26
19
0

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
26
19