简体   繁体   English

拆分字符串后要做什么?

[英]What to do after split String?

I have an IP address that I need to split in order to know the location of the device.我有一个 IP 地址,我需要拆分它才能知道设备的位置。

s = "11.19.27.55"

ip = [item[::-1] for item in s[::-1].split('.', 1)][::-1]

print(ip)

Result:结果:

['11.19.27', '55']

How can I now compare to certain parts of this result?我现在如何与此结果的某些部分进行比较? The first part I need for location second part for knowing which device it is.第一部分我需要定位第二部分以了解它是哪个设备。

I found the solution myself:我自己找到了解决方案:

print(ip[0]) for the first part print(ip[0]) 对于第一部分

print(ip[1]) for the second part第二部分的 print(ip[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM