您的位置:首页 > 编程语言 > Python开发

1 - Python 概述和基本知识

2015-09-19 15:36 405 查看

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")  #类型转换
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: