>>> a = ' 123' >>> a ' 123' >>> a.strip() '123'
>>> a = '123abc'
>>> a.strip('21')
'3abc'
>>> a.strip('12')
'3abc'
>>> str = ('www.google.com')
>>> print str
www.google.com
>>> str_split = str.split('.')
>>> print str_split
['www', 'google', 'com']
>>> str_split = str.split('.',1)
>>> print str_split
['www', 'google.com']
>>> str_split = str.split('.')[0]
>>> print str_split
www
>>> str_split = str.split('.')[::-1]
>>> print str_split
['com', 'google', 'www']
>>> str_split = str.split('.')[::]
>>> print str_split
['www', 'google', 'com']
>>> str = str + '.com.cn'
>>> str
'www.google.com.com.cn'
>>> str_split = str.split('.')[::-1]
>>> print str_split
['cn', 'com', 'com', 'google', 'www']
>>> str_split = str.split('.')[:-1]
>>> print str_split
['www', 'google', 'com', 'com']
>>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
>>> ip2num('192.168.0.1')
3232235521
>>> num2ip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)]) >>> num2ip(3232235521) '192.168.0.1'
>>> import socket >>> import struct >>> int_ip = 123456789 >>> socket.inet_ntoa(struct.pack(‘I',socket.htonl(int_ip)))#整数转换为ip地址 ‘7.91.205.21' >>> str(socket.ntohl(struct.unpack(“I”,socket.inet_aton(“255.255.255.255″))[0]))#ip地址转换为整数 ‘4294967295'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有