从socket模块学习中的一段奇怪代码说起 前言:在学习python标准库中的Socket模块中,发现了一段奇怪的代码. import socket def get_constants(prefix): dicts=dict((getattr(socket,n),n) for n in dir(socket) if n.startswith('IPPROTO_')) print (dicts) 疑问:上述代码中的for..in..循环语句和if 语句都没有冒号结束.为什么? 答案:因为上述“异常…