Python 変数

apple=1 #数字
print(apple)
“”””
1
“”””

apple=’iphone X’ #String
print(apple)
“”””
iphone X
“”””

a,b,c=11,12,13 #複数の変数一括定義
print(a,b,c)
“”””
11 12 13
“”””

Python – Print

Print String

>>> print(‘hello world’)
”’
hello world
”’

>>> print(‘Hello world’+’ Hello Hong Kong’)
“””
Hello world Hello Hong Kong
“””

ーーーーーーーーーーーーーーーーーーーーーーーーー
計算

>>> print(1+1)
“””
2
“””
>>> print(3-1)
“””
2
“””
>>> print(3*4)
“””
12
“””
>>> print(12/4)
“””
3.0
“””
>>> print(‘iphone’+4) #ダメ
“””
Traceback (most recent call last):
File ““, line 1, in
print(‘iphone’+4)
TypeError: Can’t convert ‘int’ object to str implicitly
“””

ーーーーーーーーーーーーーーーーーーーーーーーーー
>>> print(int(‘2’)+3) #string型’2’をint型に変換
“””
5
“””
>>> print(int(1.9)) #float型をint型に変換
“””
1
“””
>>> print(float(‘1.2’)+3) #string型’1.2’をfloat型に変換することも可能
“”””
4.2
“”””