【Python学习笔记】1.基础知识

一、获取用户输入

>>> x = input("x:")
x:3
>>> y = input("y:")
y:4
>>> print x*y

.>>> 提示符。交互式解释器执行了第一行以后,它打印出了字符“x:”,并作为新的提示符。

二、函数

  内建函数 pow() 乘方   abs() 绝对值  round() 把浮点数四舍五入为最接近的整数值  

      floor向下取整,但是需要在模块中调用  sqrt() 处理浮点数开方    

  调用函数

三、模块

  3.1 使用命令import导入模块  

>>> import math
>>> math.floor(32.9)
32.0
>>> int(math.floor(32.9))
32

>>> math.ceil(32.9)
33.0

 

3.2 from模块import函数

>>> from math import sqrt

>>> sqrt(3)
1.7320508075688772

  

  3.3 使用变量来引用函数

>>> foo = math.sqrt
>>> foo(9)
3.0

cmath模块(complex math) 

>>> import cmath
>>> cmath.sqrt(-1)
1j

>>> (1+3j) * (9+4j)
(-3+31j)

Python语言本身提供了对复数的支持