python初体验
hello word
zhangfeng:~ zhangfeng$ python Python 2.7.10 (default, Jul 30 2016, 19:40:32) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> help Type help() for interactive help, or help(object) for help about object. >>> print "hello word!" hello word!
以下为一错,已正确书写方法
>>> x=input("x:")x:34 File "<stdin>", line 1 x=input("x:")x:34 ^ SyntaxError: invalid syntax
以上为错误书写方式 >>> x=input("x:")
x:34
>>> y=input("y:")
y:42
>>> print x*y
1428
>>> 2**3
8
>>> pow(2,3)
8
注意此处为pow(2逗号3)传入2和3的意思调用pow函数
>>> abs(-10)
10
abs为absolute的简写,绝对| absəluːt
>>> import math
>>> math.floor(32.6)
32.0
>>> int(math.floor(32.6)) 此处类同于java中的将浮点类型强制转换成int整数类型
32
>>> foo=math.sqrt 将math.sqrt的对象赋给foo,
>>> foo(9) foo(9)就等于math.sqrt(9) sqrt计算平方根
3.0
>>>