Section 9.12-26, 9.129-26
1. Use of backslash and escape characters to search online
2. Input
print "how old are you?"age = raw_input()age = raw_input("how old are you?")
Result:
How old are you?
_ (Input)
How old are you? _ (Input)
print "how old are you?"raw_input(">>")
Result:
How old are you?
>> _
3. parameters, unpack, variables
from sys import argva,b,c = argvprint a,b,c
Result (the Object Name Is a. py followed by the parameter 1, 2)
A. py 1 2
Note that the number of parameter variables must correspond to the number of unincluded packages.
4. File Processing
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)
Result:
Opening the file
Truncating the file
Two lines:
Abcdef
Ghijk
There are more file operation commands
View more information
5. Functions
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")
Result:
'Fan' 'Year'
'Cool'
def add(a,b): return a-bprint add(6,2)
Result:
4
Note that the function has strict indentation requirements.