1.反斜杠以及转义字符的用法 多上网查资料
2.输入
print "how old are you?" age = raw_input() age = raw_input("how old are you?")
结果:
how old are you?
_ (输入)
how old are you?_ (输入)
print "how old are you?" raw_input(">>")
结果:
how old are you?
>>_
3.参数,解包,变量
from sys import argv a,b,c = argv print a,b,c
结果(文件名为a.py 后面参数为 1,2)
a.py 1 2
注意参数变量个数要和解包数量想对应
4.文件处理
from sys import argv file1,file2 = argv print "opening the file " a = open (file2,"w") print "truncating the file " a.truncate() print "two lines:" a.write("abcdef") a.write("\n") a.write('ghijk') a.write(\n)
结果:
opening the file
truncating the file
two lines:
abcdef
ghijk
还有更多的文件操作 各种命令
多看资料
5.函数
def print_two(*args): arg1,arg2 = args print "arg1: %r,arg2: %r")%(arg1,arg2) def print_one(arg1): print "arg1: %r"%arg1 print_two("fan","year") print_one("cool")
结果:
'fan''year'
'cool'
def add(a,b): return a-b print add(6,2)
结果:
4
注意函数有严格的缩进要求