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") #类型转换
相关文章推荐
- Sublime Text 3 搭建Python开发环境
- Python快速过滤Numpy数组中特定元素的方法
- Python中的collections模块
- Python如何调用自己写的包
- PYTHON正成为中国互联网+的核心技术驱动力
- Ubuntu下配置Python进行数据处理的环境
- win8下sublime text2的安装和对python的环境配置
- 个人Python学习笔记
- Windows平台 python 常用包的安装
- 跟Python打包相关的一些文章
- win8下python安装和环境配置
- python正则匹配目录、文件名
- python datetime模块相关 mysql 时间戳等
- Python 基础语法_Python脚本文件结构
- 使用python创建一个检测不到的自定义SSH后门
- 使用python创建一个检测不到的自定义SSH后门
- gensim文档-相似性查询
- lsi计算文档相似度
- gensim的LSI模型来计算文档的相似度
- python实现快速排序