我試圖在Python中找到關於+ =的信息,但找不到任何滿足我的東西。在例如20的研究演習中,他要求你用+ =重寫腳本。即使只是它的一個小例子,它可以取代什麼也是有幫助的。我怎麼可以重寫這個?例子20:努力學習Python
from sys import argv
script, input_file = argv
def print_all(f):
print f.read()
def rewind(f):
print f.seek(0)
def print_a_line(line, f):
print line, f.readline()
print "Here is the file: %r" % input_file
current_file = open(input_file)
print_all(current_file)
print "Now let's start from the beginning..."
rewind(current_file)
print "Here are the first three lines of the file:"
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_file.close()
'n + = 1'相當於'n = n + 1' – wvdz