>>> int(3.1415) # Truncates float to integer 3 >>> float(3) # Converts integer to float 3.0 >>> a = 3 # Name created >>> b = 4 >>> a + 1, a - 1 # Addition (3 + 1), subtraction (3 - 1) (4, 2) >>> b * 3, b / 2 # Multiplication (4 * 3), division (4 / 2) (12, 2.0) >>> a % 2, b ** 2 # Modulus (remainder), power (4 ** 2) (1, 16) >>> 2 + 4.0, 2.0 ** b # Mixed-type conversions (6.0, 16.0) >>> c * 2 Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'c' is not defined >>> b / 2 + a # Same as ((4 / 2) + 3) 5.0 >>> print(b / (2.0 + a)) # Same as (4 / (2.0 + 3)) 0.8 # repr 函数 # str 函数...
评论
发表评论