Python练习程序1

返回

c:python>python Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 01, 010, 0100 (1, 8, 64) >>> 0x01, 0x10, 0xFF (1, 16, 255) >>> oct(64), hex(64), hex(255) ('0100', '0x40', '0xff') >>> int('0100'), int('0100',8), int('0x40', 16) (100, 64, 64) >>> eval('100'), eval('0100'), eval('0x40') (100, 64, 64) >>> "%o %x %X" % (64, 64, 255) '100 40 FF' >>> import math >>> math.pi, math.e (3.1415926535897931, 2.7182818284590451) >>> mash.sin(2 * math.pi / 180) Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'mash' is not defined >>> maah.sin(2 * math.pi / 180) Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'maah' is not defined >>> math.sin(2 * math.pi / 180) 0.034899496702500969 >>> abs(-42), 2**4, pow(2,4) (42, 16, 16) >>> int(2.567), round(2.567), round(2.567,2) (2, 3.0, 2.5699999999999998) >>> c:\python>python Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> (5/2),(5/2.0),(5/-2.0),(5/-2) (2, 2.5, -2.5, -3) >>> (5//2),(5//2.0),(5//-2.0),(5//-2) (2, 2.0, -3.0, -3) >>> (9/3),(9.0/3),(9//3),(9//3.0) (3, 3.0, 3, 3.0) >>> from __future__import division File "<stdin>", line 1 from __future__import division ^ SyntaxError: invalid syntax >>> (5/2),(5/2.0),(5/-2.0),(5/-2) (2, 2.5, -2.5, -3) >>> x = 1 >>> x << 2 4 >>> x | 2 3 >>> x & 1 1 >>> 1j * 1j (-1+0j) >>> 2 + 1j * 3 (2+3j) >>> (2+1j)*3 (6+3j) >>> C:\>python 'python' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。 システムのプロパティ 詳細設定 環境変数 システム環境変数 Pathに変数値C:\Python23を追加 c:\test\python>python Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print "dead parrot sketch\n"; c:\python>python threenames.py dead parrot sketch c:\python>python threenames.py dead parrot sketch c:\python>python Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import threenames; dead parrot sketch >>> import threenames >>> threenames.b, threenames.c ('parrot', 'sketch') >>> from threenames import a,b,c >>> b,c ('parrot', 'sketch') >>> a 'dead' >>> dir(threenames) ['__builtins__', '__doc__', '__file__', '__name__', 'a', 'b', 'c'] >>> >>> a = 3 >>> b = 4 >>> a + 1, a - 1 (4, 2) >>> b * 3, b / 2 (12, 2) >>> a %2, b ** 2 (1, 16) >>> 2 + 4.0, 2.0 ** b (6.0, 16.0) >>> b / 2 + a 5 >>> print b / (2.0 + a) 0.8 >>> b / (2.0+a) 0.80000000000000004 >>> print b / (2.0 + a) 0.8 >>> num = 1 / 3.0 >>> num 0.33333333333333331 >>> print num 0.333333333333 >>> "%e" % num '3.333333e-001' >>> "%2.2f" % num '0.33' >>> # python test program import sys print sys.platform print 2 ** 100 c:\python>python test1.py win32 1267650600228229401496703205376
返回