21、函数可以返回东西

def add(a, b):
print "ADDING %d + %d" % (a, b)
return a + b
age = add(30, 5)
print "Age: %d" % age

[root@mall 21-40]# python t21.py 

ADDING 30 + 5

Age: 35

将函数配上参数值赋值给变量age


22、到现在你学到了哪些东西

=            #赋值

print        #打印

\             #转义符

\t            #制表符

\r            #回车

%r            #格式化任意字符串

%s           #格式化字符串

%d            #格式化数字

#__coding__:utf-8        #编码声明,表示此源程序是utf-8编码的

+ - * / %        #加减乘除取余

raw_input()        #从控制台输入任意字符

input()                #从控制台输入字符(要加'')

from sys import argv        #从sys模组里导入库argv

print """

"""                    #以自定义格式输出

open(file, 'rw')        #打开文件

file.read()                #读取文件

file.write()                #写入文件

file.close()                #关闭文件

\n                            #换行

from os.path import exists        #从os.path模组中导入库exists

print "%r" exists(file)        #检查file文件有没有存在,存在未True,不存在为False

len(indata)                #检查indata文件内部有多少字节

def                            #函数

def print(*args):        #定义函数,多个参数

f.seek(0)                    #

f.readline()                #读取一行数据

return                        #返回值,可使用函数赋值给变量


23-24 太简单,直接略过


25、更多更多的练习

split分割成列表

sentence = "All good things come to those who wait."

sentence.split(' ')


sorted排序


words.pop()

不指定序号,默认删除最后一个并返回值


26-28、略过


29、如果(if)

if 条件:

    执行语句        #4个空格缩进


30、Else和If

if 条件:

    执行语句

elif 条件:

    执行语句

else 条件:

    执行语句