首页 > 学院 > 开发设计 > 正文

9.129-26节

2019-11-14 17:00:57
字体:
来源:转载
供稿:网友

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 argva,b,c = argvprint a,b,c

 结果(文件名为a.py 后面参数为 1,2)

 

a.py 1 2

 

注意参数变量个数要和解包数量想对应

 

4.文件处理

from sys import argvfile1,file2 = argvprint "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"%arg1print_two("fan","year")print_one("cool")

 结果:

'fan''year'

'cool'

def add(a,b):    return a-bprint add(6,2)

 结果:
4

 

注意函数有严格的缩进要求

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表