趣学python第7章使用模块
2018-02-01 16:44
113 查看
趣学python第7章使用模块
1.time模块
=================== RESTART: C:\Python27\lianxi\2018123.py ===================
1517052225.95
打印出一串数字
更改打印函数,
Sat Jan 27 19:25:15 2018
只有打印asctime(),才显示正确的时间。这个函数的作用是作为一个字符串返回当前的日期和时间。
2.sys模块,用来输入一个值
sys中有一个特别的对象stdin标准输入,其中一个函数叫readline,可以用来读取来自键盘的一行文本输入,直到按下回车键为止。
print(sys.stdin.readline())
>>> 456
456
print(sys.stdin.readline())
>>> s
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
s
NameError: name 's' is not defined
>>>
现在加入if来判断
如果把这个判断放入到一个函数中
成立
1.time模块
import time #引入时间模块 print time.time()
=================== RESTART: C:\Python27\lianxi\2018123.py ===================
1517052225.95
打印出一串数字
更改打印函数,
print (time.asctime())
Sat Jan 27 19:25:15 2018
只有打印asctime(),才显示正确的时间。这个函数的作用是作为一个字符串返回当前的日期和时间。
2.sys模块,用来输入一个值
sys中有一个特别的对象stdin标准输入,其中一个函数叫readline,可以用来读取来自键盘的一行文本输入,直到按下回车键为止。
import sys print(sys.stdin.readline())这段代码输入数字没问题,到了字符串就报错
print(sys.stdin.readline())
>>> 456
456
print(sys.stdin.readline())
>>> s
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
s
NameError: name 's' is not defined
>>>
现在加入if来判断
import sys print('please input your age') age =int( sys.stdin.readline()) if age >= 12 and age <= 19: print (age ) else : print('it is not possible as a student'这个年龄段是个中学生,
如果把这个判断放入到一个函数中
def age_define(age): if age >= 12 and age <= 19: print (age ) else : print('it is not possible as a student') age_define(9)
成立
相关文章推荐
- 使用Visual Studio 6.0 (C/C++)开发Python扩展模块
- Python:使用getopt模块处理命令行参数[zt]
- python optparse 模块使用
- 使用 Boost.Python 嵌入 Python 模块到 C++
- Python的内存泄漏及gc模块的使用
- PYTHON 模块中使用了traceback 模块报错时的解决方法
- Python的内存泄漏及gc模块的使用
- 使用Python的MD5模块比较两个文件是否一致
- PYTHON正则表达式 re模块使用说明
- Python模块之chardir: 使用chartdir生成各种图表
- 今天犯了一个很蠢的错误,有关python的模块包的使用的
- 在python中使用c语言扩展模块的简单示例
- 使用setuptools自动安装python模块
- Python:使用getopt模块处理命令行参数
- Base64 编码原理简介和python的base64模块的使用
- PYTHON正则表达式 re模块使用说明
- 使用python的ConfigParser模块方便的读取配置文件
- 使用Python的timeit模块
- 使用Visual Studio.Net 2005开发Python扩展模块
- python模块之threading: 在python中使用多线程