语句和语法

  python语句                角色          例子

    赋值                创建引用值      a,b,c='good','bad','apple'

    调用                执行函数       log.write("spam,ham\n")

    print                打印对象       print "hello world"

    if/elif/else              选择         if "python" in text

                                   print text

    for/else              序列迭代        for x in mylist

                                   print x

    while/else             一般循环        while x>y

                                    print ”x“

    pass                空占位符        while Ture

                                    pass

    break,continue           循环跳跃        while True

                                    if not line: break

    try/except/finally          捕捉异常        try:

                                      action()

                                   except:

                                      print 'action error'

    raise                 触发异常        raise endSearch,location

    import,from             模块读取

 

posted @ 2017-02-20 14:03  David---wei  阅读(225)  评论(0编辑  收藏  举报