1. 输入输出
print("Hello World!","Python","...")
var = input("Enter a string:")
num1,num2 = eval(input("Enter two number:"))
2. 同时赋值
x, y = y, x %交换 x 和 y 的值
3. 代码换行
sum = 1 + 2 + 3 + 4 + 5 \
\+ 6 + 7
4. 基本数学运算
+
加法-
减法*
乘法/
除法//
取整**
乘幂%
求余- 增强型运算符:与等于号
=
结合起来构成简洁运算符。如+=
、-=
、*=
、/=
、//=
、%=
、**=
等。
5.类型转换和四舍五入
value = 5.6
int(value) %转为整数
round(value) %四舍五入
str(value) %转成字符串
6. 显示当前时间
import time
currentTime = time.time() #返回时间戳
totalSeconds = int(currentTime)
currentSecond = totalSeconds % 60
totalMinutes = totalSeconds // 60
currentMinute = totalMinutes % 60
totalHours = totalMinutes // 60
currentHour = totalHours % 24
print("Current time is " + str(currentHour) + ":" + str(currentMinute) + ":" + str(currentSecond) + " GMT") #类型转换