第一章 过程型程序设计快速入门

1.1  创建并运行Python程序
1.2  Python的关键要素
    数据类型 : int;   str:字符索引从 0 开始. Python中基本的数据类型是固定的。python中字符类型就是长度为1的字符串。
        Eg:mystr = “Hello,World!”
            mystr[0] = ‘M’  #error 
   
    对象引用:objectReference = value,当一个数据没有被任何对象引用时,就会被python的垃圾回收器回收。
        type()函数返回给定数据项的数据类型(或者称为"类")
       
    组合数据类型: 元组与列表,元组是固定的,创建之后不可改变;列表是可变的,看以插入和移除数据项。
        元组使用逗号创建,空元组使用空的()创建,最好使用 () 和 , 来创建元组。
            eg: "hello",
                ("hello","world")
                ()
        列表使用[]来创建.
            eg: ["hello","world"]
                [1,2,3,4,5,6,7,8,9]
                []
        一般情况下,列表和元组中只存储对象引用,而不是存储数据项。
        一些常用的函数:len(),返回对象的长度;listobj.append(otherobj) 或者 list.append(listobj,otherobj).
        pythong中有两种函数调用方式 functionName(arguments) 和 objectName.functionName(arguments).
       
    逻辑操作符:
        身份操作符 is :判断两个引用是否是指向同一个引用,is not :身份测试的反向测试
        比较操作符 :> , < , >= , <= , == , != .
            eg :a = 5
                1 <= a <= 10    -->True #是合法的
        成员操作符 in:对序列或集合的成员关系测试,not in:非成员关系测试
        逻辑操作符:and, or,都是返回决定结果的操作数而不是一个 bool 值。
                    not 返回的是bool值
       
    控制流语句:
        python中,预定义为常量Flase的表达式,特殊对象None,空序列或集合,值为 0 的数值型数据项等的布尔结果为False,其他为True
        if语句:
            if boolean_expreesion1:
                suite1
            elif boolean_expression2:
                suite2
                ...
            elif boolean_expressionN:
                suiteN
            else:
                else_suite
               
        while语句:
            while boolean_expression:
                suite
               
        for...in语句:
            for variable in iterable:
                suite
               
            iterable是可以迭代的任意数据类型。
           
        异常处理:
            try:
                try_suite
            except exception1 as variable1:
                exception_suite1
            ...
            exception exceptionN as variableN:
                exception_suiteN
               
            as variable 部分是可选的。
   
    算术操作符:+, -, *, /
        增强的赋值运算符:*=,+=
       
    输入/输出:print(),input().
   
    函数的创建与调用:
        def functionName(arguments):
            suite

posted @ 2011-05-24 19:26  小苏打  阅读(190)  评论(0编辑  收藏  举报