一、算术运算
1.四则运算
1+(100-20)/4+5*2
2.乘方运算
2**10
3.求摸运算
7%5
4.取整运算 7//5 = 1
5.绝对值函数 abs(-100)
6.导入数学函数后才能执行类似三角函数、阶乘函数、对数函数等 import math
7.三角函数: math.sin(pi/2) = 1
8.对数函数: math.log(e) = 1 (log默认以e为底)
9.阶乘函数:math.factorial(5) = 120
二、input和print函数用法
input : 接受用户输入的字符串
利用float函数将字符串转换成浮点数(注意与没转换前少了一个单引号)
利用eval函数将输入的字符作为表达式进行计算
print 输出内容
三、导入模块
关键词: import ...
或者 from...import...(对象)
或 import...as...
1.以普通方式导入
import datetime
子模块:datatime.datetime
当前时间 datatime.datetime.today()
2.导入模块中某个对象
from datatime import datatime
当前时间 datatime.today()
3.导入模块中全部对象
from datatime import *
当前时间 datetime.today()
date(2018,1,1)
4.以别名方式导入模块
import datatime as dt
dt.datetime.today()
四、语法规则