随笔 - 75  文章 - 0  评论 - 0  阅读 - 17万 

随笔分类 -  Python

Python 生成随机数
摘要:import random x = int(input('Enter a number for x: ')) --随机数最小值y = int(input('Enter a number for y: ')) --随机数最大值 n = int(input('How many numbers do yo 阅读全文
posted @ 2017-02-06 20:24 john2017 阅读(2029) 评论(0) 推荐(0) 编辑
异常处理
摘要:--raise >>> raise IOError('This is a test!') Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> raise IOError('This is a test! 阅读全文
posted @ 2017-02-06 20:14 john2017 阅读(117) 评论(0) 推荐(0) 编辑
摘要:>>> class Person: def __init__(self, name, age): self.name = name self.age = age def display(self): print(self.name, self.age) >>> p = Person('john', 阅读全文
posted @ 2017-02-06 20:13 john2017 阅读(126) 评论(0) 推荐(0) 编辑
文件处理
摘要:os.getcwd() 表示当前目录,可以换成其他目录路径 --返回当前目录中的文件夹和文件 >>> import os >>> os.listdir(os.getcwd()) ['01成品代码', '@test.py', 'addtofile1.py', 'class.py', 'class1.p 阅读全文
posted @ 2017-02-06 20:12 john2017 阅读(153) 评论(0) 推荐(0) 编辑
字符串格式
摘要:--设置字符串格式 >>> x = 0.123456789 >>> print('value : %.2f' % x) value : 0.12 >>> >>> x = 0.123456789 >>> y = 0.123456789 >>> print('x = %.2f y = %.3f' % ( 阅读全文
posted @ 2017-02-06 20:11 john2017 阅读(277) 评论(0) 推荐(0) 编辑
while
摘要:>>> i = 0 >>> while i < 10: print(i) i = i + 1 0 1 2 3 4 5 6 7 8 9 阅读全文
posted @ 2017-02-06 20:08 john2017 阅读(112) 评论(0) 推荐(0) 编辑
if
摘要:# if.py pwd = input('What is the password? ') if pwd == 'apple': print('Logging on ...') else: print('Incorrect password.') 运行结果: >>> What is the pass 阅读全文
posted @ 2017-02-06 20:07 john2017 阅读(108) 评论(0) 推荐(0) 编辑
for
摘要:>>> for i in range(5): print(i) 0 1 2 3 4 >>> for i in range(0, 5): print(i) 0 1 2 3 4 >>> for i in range(1, 5): print(i) 1 2 3 4 >>> for i in range(5 阅读全文
posted @ 2017-02-06 20:07 john2017 阅读(86) 评论(0) 推荐(0) 编辑
数据结构
摘要:--type命令 >>> type(5) <class 'int'> >>> type(5.0) <class 'float'> >>> type('abc') <class 'str'> >>> type(None) <class 'NoneType'> --序列 字符串、元组、列表 正索引从0开 阅读全文
posted @ 2017-02-06 20:00 john2017 阅读(117) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示