アットウィキロゴ

Python 基本

値の代入

>>> null = None
>>> print null
None
>>> type(null)
<type 'NoneType'>
>>> bool = True
>>> print bool
True
>>> type(bool)
<type 'bool'>
>>> int = 123
>>> print int
123
>>> type(int)
<type 'int'>
>>> int = 077 # 8進数
>>> int = 0xff # 16進数
>>> lng = 123L # 長整数
>>> print lng
123
>>> type(lng)
<type 'long'>
>>> str = 'this is string'
>>> type(str)
<type 'str'>
>>> uni = u'this is unicode string'
>>> type(uni)
<type 'unicode'>
>>> hdoc = """this
is
here
document
"""
>>> type(hdoc)
<type 'str'>
>>> arr = [1, 2, 3] # 変更可能な配列
>>> print arr[0]
>>> type(arr)
<type 'list'>
>>> tpl = (4, 5, 6) # 変更不可な配列(タプル)
>>> print tpl[0]
>>> type(tpl)
<type 'tuple'>
>>> map = {'a':1, 'b':2, 'c':3}
>>> print map['a']
>>> type(map)
<type 'dict'>
最終更新:2008年06月30日 01:13