0
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 1 year has passed since last update.

Pythonの便利技と注意点:print編

Last updated at Posted at 2022-08-30

目次に戻る

intを格納した変数を文字列と一緒に表示する技

+記号を使うとエラーが出る
>>> num = int(input('How many do you have?'))
How many do you have?3

>>> print('You have ' + num + '.')
Traceback (most recent call last):
  File "<pyshell#46>", line 1, in <module>
    print('You have ' + num + '.')
TypeError: can only concatenate str (not "int") to str
,でつなげるとエラーは出ない。但し、各項目ごとに自動でスペースが入る
>>> print('You have', num, '.')
You have 3 .

目次に戻る

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?