Python
_明镜止水_
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python练习-- condition
condition练习#!/usr/bin/env python3 # -*- coding: utf-8 -*-age=17 if age>=18: print('your age is',age) print('adult') elif age>=6: print('your age is',age) print('teenager') else: pri原创 2016-02-23 15:34:20 · 339 阅读 · 0 评论 -
Python练习-- List Comprehensions
#!/usr/bin/python # -*- coding: utf-8 -*-print('List Comprehensions!!')mylist=[x*x for x in range(1,11)] print(mylist)mylist2 = [x*x for x in range(1,10) if x%2 == 0] print(mylist2)mylist3 = [m+n for m原创 2016-02-23 19:25:23 · 435 阅读 · 0 评论 -
Python练习-- loop
#!/usr/bin/env python3 # -*- coding: utf-8 -*-names = ['Michael','Bob','Tracy'] for name in names: print(name)sum =0 for x in range(101): sum= sum+x print(sum) sum = 0 n = 99 while n > 0: s原创 2016-02-23 15:52:07 · 970 阅读 · 0 评论 -
Python练习-- list and tuple
#!/usr/bin/env python3 # -*- coding: utf-8 -*-classmates = ['Michael','Bob','Tracy'] print('classmates is:',classmates) print('len is',len(classmates)) print('classmates[0] is',classmates[0]) print('cl原创 2016-02-23 15:51:02 · 648 阅读 · 0 评论 -
Python练习-- iterator
#!/usr/bin/env python3 # -*- coding: utf-8 -*- d = {'Michael': 95,'Bob': 75,'Tracy': 85} for key in d: print(key)for ch in 'ABCD': print(ch) # 判断是否可以进行迭代 from collections import Iterable print(原创 2016-02-23 15:47:33 · 322 阅读 · 0 评论 -
Python练习-- function
#!/usr/bin/env python3 # -*- coding: utf-8 -*-n1=255 n2=1000 print("n1: %d → %s" % (n1,hex(n1))) print("n2: %d → %s" % (n2,hex(n2)))# 函数入参数据类型检查def my_abs(x): if not isinstance(x, (int,float)):原创 2016-02-23 15:46:20 · 367 阅读 · 0 评论 -
Python练习-- dict and set
#!/usr/bin/env python3 # -*- coding: utf-8 -*- d = {'Michael': 95,'Bob': 75,'Tracy': 85} print(d['Bob'])d['Adam'] = 67 print(d)print('Thomas in d?? %s' % ('Thomas' in d)) print('d.get(\'Thomas\'): %s'原创 2016-02-23 15:44:49 · 400 阅读 · 0 评论 -
Python练习--character
字符串使用#!/usr/bin/env python3 # -*- coding: utf-8 -*-s1 = 72 s2 = 85 n = 'Hello, %s, you have %.2f%% promote' % ('xiaoming', 100*(s2-s1)/s1) print(n)原创 2016-02-23 15:30:09 · 393 阅读 · 0 评论 -
Python练习-- slice
#!/usr/bin/env python3 # -*- coding: utf-8 -*-L=list(range(100)) # print(L)chip=L[10:20:2] print(chip)str='ABCDEFG' substr=str[0:3] print(substr)原创 2016-02-23 15:53:05 · 497 阅读 · 0 评论
分享