1 - Python 概述和基本知识

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")  #类型转换
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值