码迷,mamicode.com
首页 > 其他好文 > 详细

9.12 9-26节

时间:2015-09-12 16:00:49      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

 

9.12 9-26节

标签:

原文地址:http://www.cnblogs.com/cs-player1/p/4803111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!