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
BeautifulSoup4
V2EX  ›  Python

Python 学习笔记 1

  •  
  •   BeautifulSoup4 · 2016-12-23 12:46:47 +08:00 · 1425 次点击
    这是一个创建于 2683 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #运算符
    #算术运算符>比较运算符>逻辑运算符
    #算术运算符:(+,-,*,/,**,//.....)
    #比较运算符:(>,>=,<,<=)返回 bool 类型
    #赋值运算符:(+=,-=,=)
    #逻辑运算符:(and,or)返回 bool 类型或能隐示转换为 bool 类型.返回值都是 bool 类型.
    #运算符从左往右执行,当 and 满足所有条件返回最后一个结果,当 or 遇到满足条件,停止计算提前返回结果.
    #程序结构:(顺序结构:从上往下,一行一行执行)
    #单分支:
    开始
    if<条件>:
    操作
    结果
    #多分支
    开始
    if<条件>:
    操作
    elif<条件>:
    操作
    else:
    操作
    结果
    #for in 循环(遍历)
    开始
    for 元素 in 可迭代对象:
    操作
    结束
    #for else 字句(当循环没有提前退出执行 else 语句)
    #while 循环(条件循环)
    开始
    while<条件>:
    操作
    结束
    #break(立即结束循环)continue(跳过剩下部分)

    列表
    #列表是可变的,可通过下标访问列表元素
    #可用函数 list()表示
    #可用中括号定义[]
    #可通过 index 查找其中元素,从左往右查找,star,stop 可为负数,当 star 比 stop 大时抛出 VarlueError
    #当查找索引超出范围 VarlueErron
    #index 实现函数
    def index(lst,value,star = 0, stop = -1):
    x = star
    for i in lst[star:stop]:
    if i == value:
    return x
    x += 1
    raise ValueError()
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3134 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.