Python基础知识

Python学习--1.基础知识

标签(空格分隔): Python基础知识


变量

变量名包括字母、数字和下划线。变量不能以数字开头。

>>>x = 3
>>> x * 2 
输出:6

获取用户的输入

使用input函数

>>>input("The meaning of life: ")
the meaning of life: 42
输出:'42'

几个标准内建函数

1.乘方函数:pow

>>>from math import pow
>>>2**3
输出:8
>>>pow(2, 3)
输出:8

2.绝对值函数:abs

>>>from math import abs
>>>abs(-19)
19

3.四舍五入函数:round

>>>from math import round
>>>round(1.0/2.0)
1.0

4.向下取整函数:floor

>>>from math import floor
>>>floor(23.9)
23

模块

导入模块的时候使用import语句

>>>import math
>>>math.floor(23.9)
23

在确定不会导入多个同名函数(从不同的模块)的情况下,你可能不希望每次调用函数的时候都写上模块的名称。那么此时可以使用import的另外一种形式:

>>>from math import sqrt
>>>sqrt(9)
3.0
posted @ 2015-12-11 11:02  _freedom_yl  阅读(172)  评论(0编辑  收藏  举报