Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to tell if a string is a number

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Xiaobian today brings you to understand how to judge a string is a number, the knowledge points in the article are introduced in great detail. Friends who feel helpful can browse the content of the article together with Xiaobian, hoping to help more friends who want to solve this problem find the answer to the question. Let's learn the knowledge of "how to judge a character string is a number" together with Xiaobian.

The/proc directory contains the system process pid and service name.

[root@133 systeminformation]# ls /proc/1 107 112 121 128 136 1498 158 17911 1961 24594 3 37 45 50 58 68 78 87 97 devices ipmi mdstat sched_debug timer_list10 1075 113 1212 129 137 15 159 18 2 24641 30 38 4520 51 59 69 786 88 98 diskstats irq meminfo schedstat timer_stats100 108 114 122 13 138 150 16 1882 20 24643 31 39 453 52 6 7 79 89 981 dma kallsyms misc scsi tty101 10852 115 12252 130 139 151 160 19 2046 25 3164 4 454 527 60 70 8 9 99 driver kcore modules self uptime102 10854 1154 123 13046 14 152 1621 190 21 25500 3188 40 456 528 61 71 80 90 acpi execdomains keys mounts slabinfo version10275 109 116 12396 13047 140 1527 1622 191 21678 26 3190 409 46 53 62 72 81 91 buddyinfo fb key-users mpt softirqs vmallocinfo10295 11 117 12398 131 141 153 1655 1951 21697 27 32 41 4665 54 63 73 82 92 bus filesystems kmsg mtd#defines a function to determine whether it is a number [root@133 systeminformation]# vim isNum.py#!/ usr/bin/env pythonimport sysimport osimport stringdef isNum(s): for i in s: if i in string.digits: continue else: return False return Truefor pid in os.listdir('/proc'): if isNum(pid): print pid In [5]: import stringIn [6]: string.digits #Determine whether it is a digit Out[6]: '0123456789'[root@133 systeminformation]# python isNum.py #Print only digits, exclude letters 123456789In [8]: for pid in os.listdir ('/proc'): #Use pid.isdigit() to determine whether it is a digit ...: if pid.isdigit(): ...: print pid ...: 123456 Thank you for reading, the above is "how to judge a character string is a number" all the content, learn friends hurry to operate it. I believe that Xiaobian will definitely bring you better quality articles. Thank you for your support of the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report