1.反斜杠以及轉(zhuǎn)義字符的用法 多上網(wǎng)查資料
2.輸入
結(jié)果:
how old are you?
_ (輸入)
how old are you?_ (輸入)
print "how old are you?"raw_input(">>")結(jié)果:
how old are you?
>>_
3.參數(shù),解包,變量
from sys import argva,b,c = argvprint a,b,c
結(jié)果(文件名為a.py 后面參數(shù)為 1,2)
a.py 1 2
注意參數(shù)變量個(gè)數(shù)要和解包數(shù)量想對(duì)應(yīng)
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)結(jié)果:
opening the file
truncating the file
two lines:
abcdef
ghijk
還有更多的文件操作 各種命令
多看資料
5.函數(shù)
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")結(jié)果:
'fan''year'
'cool'
def add(a,b): return a-bprint add(6,2)
結(jié)果:
4
注意函數(shù)有嚴(yán)格的縮進(jìn)要求
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注