使用 Python 进行 socket 编程 体验 Python 下面我们先对 Python 是什么建立一个直观印象
作为一种解释性语言,Python 很容易使用,并且能够快速验证我们的想法和开发原型软件
Python 程序可以作为一个整体进行解释,也可以一行行地解释
可以在第一次运行 Python 时测试一下下面的 Python 代码,然后一次只输入一行试试
在 Python 启动之后,会显示一个提示符(>>>),可以在这里输入命令
注意在 Python 中,缩进非常重要,因此代码前面的空格不能忽略: 清单 1
可以试验的几个 Python 例子 # Open a file, read each line, and print it out for line in open('file
txt'): print line # Create a file and write to it file = open("test
txt", "w") file
write("test line\n") file
close() # Create a small dictionary of names and ages and manipulate family = {'Megan': 13, 'Elise': 8, 'Marc': 6} # results in 8 family['Elise'] # Remove the key/value pair del family['Elise'] # Create a list and a function that doubles its input
Map the # function to each o