V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yechengzhe
V2EX  ›  Python

有哪些或者教程可以很好的入门 Python ?

  •  
  •   yechengzhe · 2017-07-30 03:46:35 +08:00 · 4220 次点击
    这是一个创建于 2434 天前的主题,其中的信息可能已经有所发展或是发生改变。
    20 条回复    2017-08-02 16:33:10 +08:00
    afpro
        1
    afpro  
       2017-07-30 04:32:14 +08:00   ❤️ 1
    找一个现实的需求 比如批量处理数据 处理文件之类的鼓捣 了解一下语法和常用功能 然后看包管理 装饰器之类的‘高阶’概念 然后了解一下虚拟机处理流程 举个例子
    def append(v, ary=[]):
    ary.append(v)
    return ary

    print(append(1)) # 结果是 [1]
    print(append(2)) # 结果是 [1, 2]
    这段代码整明白就能弄明白很多事情了(当然了,实际工程里这么写代码会被打死的)
    然后就可以再了解一下 GC 啊 GIL 之类的
    然后就 Cython PyPy 之类的边角料
    在之后就是 Django flask spark 之类的具体应用
    afpro
        2
    afpro  
       2017-07-30 04:32:43 +08:00
    @afpro 代码没有缩进 你凑合着看吧
    RqPS6rhmP3Nyn3Tm
        3
    RqPS6rhmP3Nyn3Tm  
       2017-07-30 04:34:57 +08:00 via iPhone   ❤️ 1
    廖雪峰,系列教程都很棒。
    我就是看他的教程学会的 py 和 git
    davy1995
        4
    davy1995  
       2017-07-30 05:23:03 +08:00 via Android
    @BXIA 但是他 git 教程感觉。。真的很一般吧
    xiayibu
        5
    xiayibu  
       2017-07-30 06:25:20 +08:00
    跟孩子一起学编程
    vainpray
        6
    vainpray  
       2017-07-30 07:39:21 +08:00
    我也是自学的 python,最初的时候是下载了一套相对比较新的视频讲座,用来掌握基本语法和一些编程思路
    基础知识掌握了之后,以需求为导向,实际上手,一点点针对遇到的问题不断的 google (不要百度…对…不要百度…),多上 Stack Overflow,受益良多的
    Antidictator
        7
    Antidictator  
       2017-07-30 09:03:49 +08:00 via Android
    @davy1995 没有对比就没有伤害,不过单从上手容易程度上看,有一个 GitHub 项目专门介绍 Git 更容易上手点
    ifane
        8
    ifane  
       2017-07-30 09:17:48 +08:00
    看廖雪峰的,有的地方没看懂就去搜其他人讲的。
    看他的目录,我觉得节奏还挺好的,可以按照他目录的顺序来学。
    gulangyu
        9
    gulangyu  
       2017-07-30 10:04:35 +08:00 via Android
    @vainpray 赞同~差不多入门后,遇到有难解决的问题,就把错误代码复制进 google,一般开头几条搜索结果就是 stackoverflow 的,效率超高~
    zetary
        10
    zetary  
       2017-07-30 10:09:57 +08:00 via Android
    看一下廖雪峰的教程就开始多用吧…
    YidaZh
        11
    YidaZh  
       2017-07-30 10:14:43 +08:00
    我也自学,看完 A Byte of Python 后,目前正在刷 Code Wars,刷完后准备上爬虫了,Web 应用不打算刷了。
    clino
        12
    clino  
       2017-07-30 10:17:18 +08:00
    慕课网找些教程过一遍?
    http://www.imooc.com/course/list?c=python
    RqPS6rhmP3Nyn3Tm
        13
    RqPS6rhmP3Nyn3Tm  
       2017-07-30 10:38:14 +08:00 via iPad
    @davy1995 作者自己也说了,不是 git 专家,但是都是自己的经验。从一个使用者的角度来说我觉得还是相当实用的
    xyjiangtou
        14
    xyjiangtou  
       2017-07-30 10:44:04 +08:00
    @Antidictator
    @BXIA
    放个链接额
    secondwtq
        15
    secondwtq  
       2017-07-30 12:51:52 +08:00 via Android
    我觉得 Git 比 Python 难学多了 …
    onlyhot
        16
    onlyhot  
       2017-07-30 13:01:39 +08:00 via iPhone
    怎么学正则表达式,心里有阴影了
    lleon
        17
    lleon  
       2017-07-30 13:45:08 +08:00
    @onlyhot
    下一个 RegexBuddy 软件,它帮助里自带的 tutorials 是最好的正则表达式教程。
    另外,最好背下元字符表:
    . * ? + ( ) [ ^ $ | \
    口决:点星问号加,小中大括号,头尾竖杠。

    以前写的 Python 正则表达式笔记:
    (参考资料:廖雪峰 Python 教程、正则指引)

    re 模块包含所有正则表达式的功能。

    在正则表达式内部插入匹配模式:

    对大小写不敏感:(?i)
    单行模式,即.匹配'\n':(?s)
    多行模式:(?m)
    ASCII 模式,即\d、\w、\s 不会匹配非 ASCII 数字,字母和空格:(?a)
    Unicode 模式,与 ASCII 模式相反,Python 3 的默认模式:(?u)
    注释模式:(?x)

    注意:Python 中的模式永远是对整个正则表达式生效的,无论(?...)出现在哪里; Python 不支持用(?-...)停用模式。

    \A 匹配字符串的开始位置,\Z 匹配字符串的结束位置。Python 没有\z,\Z 相当于其它语言正则表达式的\z。
    如果使用了命名分组,在正则表达式中应当使用(?P=name)来引用,在替换时应当使用\g<name>来引用。例如:r'(?P<char>[a-z])(?P=char)'

    观察某个正则表达式的详细信息:

    >>> re.compile(r'(ab|[cde])+', re.DEBUG)
    max_repeat 1 2147483647
    subpattern 1
    branch
    literal 97
    literal 98
    or
    in
    literal 99
    literal 100
    literal 101

    re.compile('(ab|[cde])+', re.DEBUG)

    Match 对象常用的方法和属性:

    import re
    m = re.search(r'(\d{4})-(\d{2})-(\d{2})', '2010-12-20')
    print('%s start at %d and ends at %d' % (m.group(), m.pos, m.endpos))
    for i in range(1, m.lastindex + 1): # 最大分组的编号
    print('%s start at %d and ends at %d' %
    (m.group(i), m.start(i), m.end(i)))
    print(m.expand(r'year:\1 month:\2 day:\3'))

    运行结果:

    2010-12-20 start at 0 and ends at 10
    2010 start at 0 and ends at 4
    12 start at 5 and ends at 7
    20 start at 8 and ends at 10
    year:2010 month:12 day:20

    常用操作示例:

    import re

    # 1. 验证与搜索

    # 如果找到,search()方法返回一个 Match 对象,否则返回 None
    if re.search(r'\A\d{4}-\d{2}-\d{2}\Z', '2010-12-20'):
    print('ok')

    # 如果一个正则表达式要反复使用,可以先编译它,以提高效率
    dateRegex = re.compile(r'\A\d{4}-\d{2}-\d{2}\Z')
    if dateRegex.search('2010-12-20'): # 或 re.search(dateRegex, '2010-12-20')
    print('ok')

    # Match 对象的 group()和 groups()方法
    phoneNumRegex = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)')
    m = phoneNumRegex.search('My number is 415-555-4242.')
    print(m.group()) # 输出:415-555-4242
    print(m.group(0)) # 输出:415-555-4242
    print(m.group(1)) # 输出:415
    print(m.group(2)) # 输出:555-4242
    # 一次性获取从 1 开始的所有的分组
    print(m.groups()) # 输出:('415', '555-4242')

    # match()和 search()非常相似,参数和返回值都相同,唯一的区别在于:
    # match()只会从字符串的最左端开始匹配,search()则没有这个限制。

    # 2. 提取

    # findall()方法返回一个字符串列表或一个元组列表,没找到则返回一个空列表
    print(re.findall(r'\d{4}-\d{2}-\d{2}', '2010-12-20 2011-02-14'))
    # 输出:['2010-12-20', '2011-02-14']
    print(re.findall(r'(\d{4})-(\d{2})-(\d{2})', '2010-12-20 2011-02-14'))
    # 输出:[('2010', '12', '20'), ('2011', '02', '14')]

    # 使用 finditer()迭代查找
    for iter in re.finditer(r'(\d{4})-(\d{2}-(\d{2}))', '2010-12-20 2011-02-14'):
    print(iter.group()) # iter 是一个 Match 对象
    # 输出:2010-12-20
    # 输出:2011-02-14

    # 使用命名分组
    regex = re.compile(r'(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})')
    for iter in regex.finditer('2010-12-20 2011-02-14'):
    print(iter.group('year'), iter.group('month'), iter.group('day'))

    # 3. 替换

    print(re.sub(r'\d+', r'**', 'She is 22 years old.'))
    # 输出:She is ** years old.

    regex = r'(\d{4})-(\d{2})-(\d{2})'
    replacement = r'\2/\3/\1' # 或 r'\g<2>/\g<3>/\g<1>'
    print(re.sub(regex, replacement, '2010-12-20'))
    # 输出:12/20/2010

    # 使用命名分组
    regex = r'(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})'
    replacement = r'\g<month>/\g<day>/\g<year>'
    print(re.sub(regex, replacement, '2010-12-20'))
    # 输出:12/20/2010

    # 在替换中使用整个表达式匹配的文本
    regex = r'\d+.\d{0,2}'
    replacement = r'$\g<0>'
    print(re.sub(regex, replacement, 'the price is 12.99'))
    # 输出:the price is $12.99

    # 指定替换操作最多发生的次数:
    print(re.sub(r'\d+', 'x', '13 + 76 = 89', 1))
    # 输出:x + 76 = 89

    # 将所有单词统一为首字母大写其余字母小写格式:
    def capitalize(match):
    return match.group(1).upper() + match.group(2).lower()
    result = re.sub(r'(?i)\b([a-z])([a-z]+)\b', capitalize, 'one tWO THREE')
    print(result)
    # 输出:One Two Three

    # 4. 切分字符串
    print(re.split(r'\s+', 'a b \t\r\n c '))
    # 输出:['a', 'b', 'c', '']
    xudzhang
        18
    xudzhang  
       2017-07-30 21:48:57 +08:00   ❤️ 1
    话说楼主的头像真的很赞!
    Antidictator
        19
    Antidictator  
       2017-08-01 12:55:35 +08:00
    @xyjiangtou 不好意思, 找了很久没找到,刚才在睡觉的时候突然想起来,然后 Google 了一下 How to learn git,第一个就是: https://try.github.io/levels/1/challenges/1 :)
    kevanbin
        20
    kevanbin  
       2017-08-02 16:33:10 +08:00
    简明 Python 教程
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2657 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:21 · PVG 23:21 · LAX 08:21 · JFK 11:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.