整数型


In [1]:
2 + 2


Out[1]:
4

In [2]:
3 - 8


Out[2]:
-5

In [3]:
6 * 9


Out[3]:
54

In [4]:
8 / 2


Out[4]:
4.0

In [5]:
5 % 2


Out[5]:
1

In [6]:
5 ** 2


Out[6]:
25

In [7]:
10 / 3


Out[7]:
3.3333333333333335

In [8]:
10 // 3


Out[8]:
3

浮動小数点型


In [9]:
5.0


Out[9]:
5.0

In [10]:
5.0 + 5.2


Out[10]:
10.2

In [11]:
10.2 + 8


Out[11]:
18.2

文字列型


In [12]:
'Hello,world'


Out[12]:
'Hello,world'

In [13]:
"Hello,world"


Out[13]:
'Hello,world'

In [14]:
'吾輩は蛇である'


Out[14]:
'吾輩は蛇である'

In [15]:
print('I\'m Hiroki')


I'm Hiroki

In [16]:
print('Hello\nworld')


Hello
world

In [17]:
"""foo
bar
baz
"""


Out[17]:
'foo\nbar\nbaz\n'

In [18]:
'Mt.' + 'Fuji'


Out[18]:
'Mt.Fuji'

In [19]:
'スパム' * 5


Out[19]:
'スパムスパムスパムスパムスパム'

In [20]:
'python'[1]


Out[20]:
'y'

In [21]:
'python'[2:5]


Out[21]:
'tho'

In [22]:
'python'[:3]


Out[22]:
'pyt'

In [23]:
'python'[4:]


Out[23]:
'on'

In [24]:
len('python')


Out[24]:
6

In [25]:
't' in 'python'


Out[25]:
True

In [26]:
'k' in 'python'


Out[26]:
False

In [27]:
'th' in 'python'


Out[27]:
True

In [28]:
'pain-au-chocolat'.split('-')


Out[28]:
['pain', 'au', 'chocolat']

In [29]:
'-'.join(['pain', 'de', 'campagne'])


Out[29]:
'pain-de-campagne'

バイト型


In [30]:
b'\x89PNG\r\n\x1a\n'


Out[30]:
b'\x89PNG\r\n\x1a\n'

In [31]:
"日本".encode('utf-8')


Out[31]:
b'\xe6\x97\xa5\xe6\x9c\xac'

In [32]:
b'\xe6\x97\xa5'.decode('utf-8')


Out[32]:
'日'