開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 5.(Numeric Types)、Test Your Knowledge: Quiz 8.を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 8.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- for n in range(20): print('{0} octal: {1}, hexadecimal: {2}, binary: {3}'.format( n, oct(n), hex(n), bin(n)))
入出力結果(Terminal, IPython)
$ ./sample8.py 0 octal: 0o0, hexadecimal: 0x0, binary: 0b0 1 octal: 0o1, hexadecimal: 0x1, binary: 0b1 2 octal: 0o2, hexadecimal: 0x2, binary: 0b10 3 octal: 0o3, hexadecimal: 0x3, binary: 0b11 4 octal: 0o4, hexadecimal: 0x4, binary: 0b100 5 octal: 0o5, hexadecimal: 0x5, binary: 0b101 6 octal: 0o6, hexadecimal: 0x6, binary: 0b110 7 octal: 0o7, hexadecimal: 0x7, binary: 0b111 8 octal: 0o10, hexadecimal: 0x8, binary: 0b1000 9 octal: 0o11, hexadecimal: 0x9, binary: 0b1001 10 octal: 0o12, hexadecimal: 0xa, binary: 0b1010 11 octal: 0o13, hexadecimal: 0xb, binary: 0b1011 12 octal: 0o14, hexadecimal: 0xc, binary: 0b1100 13 octal: 0o15, hexadecimal: 0xd, binary: 0b1101 14 octal: 0o16, hexadecimal: 0xe, binary: 0b1110 15 octal: 0o17, hexadecimal: 0xf, binary: 0b1111 16 octal: 0o20, hexadecimal: 0x10, binary: 0b10000 17 octal: 0o21, hexadecimal: 0x11, binary: 0b10001 18 octal: 0o22, hexadecimal: 0x12, binary: 0b10010 19 octal: 0o23, hexadecimal: 0x13, binary: 0b10011 $
0 コメント:
コメントを投稿