欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

day31-python之内置函数

程序员文章站 2022-06-14 10:19:49
1.udp多线程 2.内置函数 ......

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))