開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART II.(Types and Operations)、CHAPTER 5(Numeric Types)、Test Your Knowledge: Quiz 1, 2, 3, 4, 5, 6, 7, 8, 9を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 1, 2, 3, 4, 5, 6, 7, 8, 9
入出力結果(Terminal)
$ python3 Python 3.3.3 (default, Dec 2 2013, 01:40:21) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 2 * (3 + 4) # 14 14 >>> 2 * 3 + 4 # 10 10 >>> 2 + 3 * 4 # 14 14 >>> import math >>> math.sqrt(4) 2.0 >>> math.sqrt(2) 1.4142135623730951 >>> 2 ** 2 4 >>> pow(2, 2) 4 >>> type(1 + 2.0 + 3) # float <class 'float'> >>> round <built-in function round> >>> round(1.4) 1 >>> round(1.5) 2 >>> dir(math) ['__doc__', '__file__', '__loader__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'] >>> math.trunc(1.4) 1 >>> math.trunc(1.5) 1 >>> int(1.4) 1 >>> int(1.5) 1 >>> math.floor(1.4) 1 >>> math.floor(1.5) 1 >>> float(1) 1.0 >>> 1/1.0 1.0 >>> oct(8) '0o10' >>> hex(16) '0x10' >>> bin(2) '0b10' >>> int('10', 8) 8 >>> int('10', 16) 16 >>> int('10', 2) 2 >>> quit() $
0 コメント:
コメントを投稿