LoginSignup
0
0

More than 1 year has passed since last update.

変数に複数行の文字列を代入

Posted at

自分用の備忘録です。

トリプルクウォート""", '''を使う

シングルクウォート'またはダブルクウォート"を3つ連続させて、文字列を囲う。

ipython
In [12]: s = ''' 
    ...: a b c d e 
    ...: f g h i j 
    ...: k l m n o 
    ...: '''                                                                                                                                                         

改行も反映される。
クリップボードからサクッと貼り付けたい場合に便利。

ipython
In [13]: s                                                                                                                                                           
Out[13]: '\na b c d e\nf g h i j\nk l m n o\n'

In [14]: print(s)                                                                                                                                                    

a b c d e
f g h i j
k l m n o

注意点としては、プログラムが見にくくなるため推奨はされないらしい。

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