Python の組み込み関数シーエイチアール chr() の『使用例』と『エラー例』です。
chr() に、各種オブジェクトを渡しました。
chr() でエラーになったコード例
chr() でエラーになったコード例です。
Python 公式マニュアル
chr()
Traceback (most recent call last):
...
TypeError: chr() takes exactly one argument (0 given)
chr(None)
Traceback (most recent call last):
...
TypeError: an integer is required (got type NoneType)
chr(-1)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr(1114112)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr(0x110000)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr(-1.0)
Traceback (most recent call last):
...
TypeError: integer argument expected, got float
chr(0.0)
Traceback (most recent call last):
...
TypeError: integer argument expected, got float
chr(1.0)
Traceback (most recent call last):
...
TypeError: integer argument expected, got float
chr(complex(0.0, 0.0))
Traceback (most recent call last):
...
TypeError: can't convert complex to int
chr(complex(0.0, 1.0))
Traceback (most recent call last):
...
TypeError: can't convert complex to int
chr(complex(1.0, 0.0))
Traceback (most recent call last):
...
TypeError: can't convert complex to int
chr(complex(1.0, 1.0))
Traceback (most recent call last):
...
TypeError: can't convert complex to int
chr('')
Traceback (most recent call last):
...
TypeError: an integer is required (got type str)
chr('1')
Traceback (most recent call last):
...
TypeError: an integer is required (got type str)
chr(())
Traceback (most recent call last):
...
TypeError: an integer is required (got type tuple)
chr([])
Traceback (most recent call last):
...
TypeError: an integer is required (got type list)
chr(set())
Traceback (most recent call last):
...
TypeError: an integer is required (got type set)
chr({})
Traceback (most recent call last):
...
TypeError: an integer is required (got type dict)
chr(range(0))
Traceback (most recent call last):
...
TypeError: an integer is required (got type range)
chr(b'')
Traceback (most recent call last):
...
TypeError: an integer is required (got type bytes)
chr(b'0')
Traceback (most recent call last):
...
TypeError: an integer is required (got type bytes)
chr(b'1')
Traceback (most recent call last):
...
TypeError: an integer is required (got type bytes)
chr(lambda x: x)
Traceback (most recent call last):
...
TypeError: an integer is required (got type function)
import datetime
chr(datetime.datetime.max)
Traceback (most recent call last):
...
TypeError: an integer is required (got type datetime.datetime)
import datetime
chr(datetime.date.max)
Traceback (most recent call last):
...
TypeError: an integer is required (got type datetime.date)
import datetime
chr(datetime.time.max)
Traceback (most recent call last):
...
TypeError: an integer is required (got type datetime.time)
import datetime
chr(datetime.timedelta(0))
Traceback (most recent call last):
...
TypeError: an integer is required (got type datetime.timedelta)
chr() に int(10 進数表示)
chr() に、-1 から 1114112 までの値を使用したコード例です。
引数に 10 進数表示を使いました。
Python 公式マニュアル
chr(-1)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr(0)
'\x00'
chr(1)
'\x01'
chr(2)
'\x02'
chr(3)
'\x03'
chr(4)
'\x04'
chr(5)
'\x05'
chr(47)
'/'
chr(48)
'0'
chr(49)
'1'
chr(64)
'@'
chr(65)
'A'
chr(66)
'B'
chr(96)
'`'
chr(97)
'a'
chr(98)
'b'
chr(254)
'þ'
chr(255)
'ÿ'
chr(256)
'Ā'
chr(1114110)
'\U0010fffe'
chr(1114111)
'\U0010ffff'
chr(1114112)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr() に int(16 進数表示)
chr() に、-0x1 から 0x110000 までの値を使用したコード例です。
引数に 16 進数表示を使いました。
Python 公式マニュアル
chr(-0x1)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)
chr(0x0)
'\x00'
chr(0x1)
'\x01'
chr(0x2)
'\x02'
chr(0x3)
'\x03'
chr(0x4)
'\x04'
chr(0x5)
'\x05'
chr(0x2f)
'/'
chr(0x30)
'0'
chr(0x31)
'1'
chr(0x40)
'@'
chr(0x41)
'A'
chr(0x42)
'B'
chr(0x60)
'`'
chr(0x61)
'a'
chr(0x62)
'b'
chr(0xfe)
'þ'
chr(0xff)
'ÿ'
chr(0x100)
'Ā'
chr(0x10fffe)
'\U0010fffe'
chr(0x10ffff)
'\U0010ffff'
chr(0x110000)
Traceback (most recent call last):
...
ValueError: chr() arg not in range(0x110000)