Python简单介绍

1,183 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,183
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
23
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Python简单介绍

  1. 1. Python 简单介绍 Guixing Bai guixing@staff.sina.com.cn 1
  2. 2. 特点 2
  3. 3. 简单易学 3
  4. 4. 功能强大 4
  5. 5. 兼容性好 5
  6. 6. 扩展性好 6
  7. 7. 开源 7
  8. 8. 例子 8
  9. 9. 好工具 iPython 9
  10. 10. 内建函数 build-in 10
  11. 11. print 11
  12. 12. open, range, lambda 12
  13. 13. map, filter 13
  14. 14. 模块 14
  15. 15. sys,os 15
  16. 16. time, datetime 16
  17. 17. hashlib 17
  18. 18. Tips 18
  19. 19. [i for i in lst if i] 19
  20. 20. [i.strip() for i in lst if i] 20
  21. 21. def fun(arg1,arg2) d={arg1:11,arg2:22} fun(d[arg1],d[arg2]) fun(**d) 21
  22. 22. p = [a,b,c] #want a/b/c os.path.join(*p) 22
  23. 23. a=[a,b,c] #want a_b_c or a*b*c ’_’.join(a) ’*’.join(a) b=’fuck’ #want fuck! fuck!... ”%s! ” % (b) * 20 23
  24. 24. 源代码 style guide 24
  25. 25. tab,space 25
  26. 26. def fun(): tab>a=xx ....return a 26
  27. 27. 好 4个space 27
  28. 28. #!/usr/bin/env python # coding=utf-8 # -*- coding: utf-8 -*- 28
  29. 29. #NO import os,sys #Yes import os import sys #But from os import popen,popen2 29
  30. 30. #Yes a = 1 + 2 blockq = 3 + 4 #No a = 1 + 2 blockq = 3 + 4 30
  31. 31. 1行不超79 etc. 31
  32. 32. Py3k has come 32
  33. 33. Style Changes 33
  34. 34. 4-space ONLY 34
  35. 35. • None, as 成了关键字 • print 成了函数 • dict.has_key 改用in操作符 • int和long没有差别了 • 所有的strings都是Unicode • 不可比的类型之间比较将出异常 • <>操作符没有了,!=代替 • apply()用f(*args,**kw)代替 • xrange()用rang()代替 • map和filter没有了,list可以管 • etc. 35
  36. 36. Module Changes 36
  37. 37. • Removed • sha,md5: hashlib代替 • mimetools: email package代替 • timing: time.clock()代替 • Renamed • cPickle: _pickle • StringIO/cStringIO: 成了io的一个class • HTMLParser: http.client • BaseHTTPServer: http.server • CGIHTTPServer: http.server • SimpleHTTPServer: http.server 37
  38. 38. 路漫漫其 修远兮! 38
  39. 39. Q&A? 39
  40. 40. 参考资料 • PEP: http://www.python.org/dev/peps/ • 8: Style Guide for Python Code • 3000: Python 3000 • 263: Defining Python Source Code Encodings • Py3k: http://wiki.python.org/moin/ Python3.0 • Python Shell Tab Completion: http:// blog.yzlin.org/2008/12/22/75/ 40
  41. 41. • iPython: http://ipython.scipy.org/moin/ • python常用模块: http:// wiki.woodpecker.org.cn/moin/ PyCommonUsageMod • python中文处理: http:// wiki.woodpecker.org.cn/moin/PyInChinese • Python编辑速度技巧: http:// wiki.woodpecker.org.cn/moin/PyOptimize • vim的tabstop: http://blog.khsing.net/ 2008/12/vims-tabstop.html 41
  42. 42. Thanks! 42

×