1.udp多线程

import socketserver

class MyServer(socketserver.BaseRequestHandler):
def handle(self):
print(self.request)
print('收到客户端的消息是',self.request[0])
self.request[1].sendto(self.request[0].upper(),self.client_address) if __name__ == '__main__':
s=socketserver.ThreadingUDPServer(('127.0.0.1',8086),MyServer) #多线程
s.serve_forever()
from socket import *
ip_port=('127.0.0.1',8086)
buffer_size=1024 udp_client=socket(AF_INET,SOCK_DGRAM) #数据报 while True:
msg=input('>>: ').strip()
udp_client.sendto(msg.encode('utf-8'),ip_port) data,addr=udp_client.recvfrom(buffer_size)
# print(data.decode('utf-8'))
print(data)
from socket import *
ip_port=('127.0.0.1',8086)
buffer_size=1024 udp_client=socket(AF_INET,SOCK_DGRAM) #数据报 while True:
msg=input('>>: ').strip()
udp_client.sendto(msg.encode('utf-8'),ip_port) data,addr=udp_client.recvfrom(buffer_size)
# print(data.decode('utf-8'))
print(data)

2.内置函数

# # 三元运算
# # a = 1
# # result = "xiaoming" if a == 1 else "xiaogang"
# # print(result)
# #
# # lambda 表达式
#
# # def func(arg):
# # return arg + 1
# # print(func(2))
# # # func = lambda *args : print(args)
# # print(func(1,2,3))
# # # map
# # li = [1,2,3,4,5]
# # def func(s):
# # return s + 1
# # ret = map(func,li)
# # print(list(ret))
#
# # print(list(map(lambda li : li + 1 ,li)))
# # # filter 过滤
#
# # li = [22,33,44,55]
# #
# # def func(s):
# # if s > 33:
# # return s
# # ret = filter(func,li)
# # print(list(ret))
# #
# # print(list(filter(lambda s : s >33 ,li)))
# # # reduce
#
from functools import reduce
#
# # li = ["a","l","e","x"]
# # def func(a,b):
# # return a+b
# # ret = reduce(func,li)
# # print(ret)
#
# li = [1,2,3,4,5]
# print(reduce(lambda a,b : a +b ,li))
#
#
li = [1,2,3,4,5]
print(reduce(lambda a, b: a + b, li))
05-11 22:27