(一)第一个python语句、乘除法、获取用户输入、函数

一、print语句

>>> print "hello World!!"
  • python2 和python3 的print是不一样的,python3的print(“hello world!”)

二、加减乘除

>>> 1/2
0
  • 结果是0,可见pathon2中默认是取整,如果要精确求值的话(结果精确到小数点),有以下两种方法:
    •   1. 除数或者被除数中含有浮点数,则结果也是浮点数。
>>> 1.0/2
0.5
    •   2. 用 from __future__ import division 定义
>>> from __future__ import division
>>> 1/2
0.5
>>> 
>>> 2*33
66
>>> 2**3
8
  • **代表次方。

三、用户输入

>>> x=input("x:")
x:5
>>> y=input("y:")
y:6
>>> print x*y
30

四、函数

  • 次方函数pow,相当于 **

>>> pow(2,3)
8
  • 绝对值函数

>>> abs(-10)
10
  • 四舍五入取整

>>> round(5.2)
5.0
>>> round(5.6)
6.0

 

原文地址:https://www.cnblogs.com/shyroke/p/7455372.html