{"id":420,"date":"2017-02-27T17:30:35","date_gmt":"2017-02-27T08:30:35","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=420"},"modified":"2021-10-19T22:36:03","modified_gmt":"2021-10-19T13:36:03","slug":"%e6%96%87%e5%ad%97%e5%88%97%e3%81%ae%e7%a8%ae%e5%88%a5%e5%88%a4%e5%ae%9a%e3%81%a8%e6%95%b0%e5%80%a4%e5%a4%89%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/420","title":{"rendered":"\u6587\u5b57\u5217\u306e\u5224\u5b9a\u7cfb\u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"<p>Python\u306e\u6587\u5b57\u5217\u306b\u306fis\uff5e\u3068\u3044\u3046\u7a2e\u5225\u306e\u5224\u5225\u7528\u30e1\u30bd\u30c3\u30c9\u304c\u591a\u6570\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u5224\u5b9a\u30e1\u30bd\u30c3\u30c9<\/h2>\n<p>Python\u306e\u6587\u5b57\u5217\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6587\u5b57\u5217\u306e\u7a2e\u5225\u306e\u5224\u5b9a\u7528\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u30021\u6587\u5b57\u4ee5\u4e0a\u3067\u306a\u304a\u304b\u3064\u3059\u3079\u3066\u306e\u6587\u5b57\u304c\u6761\u4ef6\u3092\u6e80\u305f\u3057\u3066\u3044\u308b\u5834\u5408\u3001True\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>isalnum\uff1a\u82f1\u5b57or\u6570\u5b57<\/li>\n<li>isalpha\uff1a\u82f1\u5b57<\/li>\n<li>isascii\uff1aASCII\u6587\u5b57<\/li>\n<li>isdigit\uff1aASCII\u6587\u5b57\u306e\u6570\u5b57<\/li>\n<li>isdecimal\uff1a10\u9032\u6570\u306e\u6570\u5b57<\/li>\n<li>isnumeric\uff1a\u6570\u3092\u8868\u3059\u6587\u5b57<\/li>\n<li>islower\uff1a\u5b50\u6587\u5b57<\/li>\n<li>isupper\uff1a\u5927\u6587\u5b57<\/li>\n<\/ul>\n<h3>isalnum\u3068isalpha<\/h3>\n<p>\u305f\u3060\u3057\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u304cisalnum\u3068isalpha\u3067\u3059\u3002\u3053\u3053\u3067\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b\u82f1\u5b57\u3068\u306f\u300cUnicode \u6587\u5b57\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067 \"Letter\" \u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u300d\u3067\u3042\u308b\u305f\u3081\u3001\u3044\u308f\u3086\u308b\u5168\u89d2\u6587\u5b57\u7b49\u3067\u3082\u82f1\u5b57\u3068\u3057\u3066\u6271\u308f\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u3001\u7d14\u7c8b\u306a\u82f1\u5b57\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u306e\u5224\u5225\u306fisascii\u3068\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u306a\u3069\u306e\u5de5\u592b\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u306fisalnum\u3001isalpha\u306e\u4f7f\u7528\u3057\u3066\u6319\u52d5\u3092\u6bd4\u8f03\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u534a\u89d2\u82f1\u6570\u5b57 \r\nprint(&quot;1a&quot;.isalnum()) # True\r\nprint(&quot;1a&quot;.isalpha()) # False\r\n\r\n# \u534a\u89d2\u82f1\u5b57\r\nprint(&quot;a&quot;.isalnum()) # True\r\nprint(&quot;a&quot;.isalpha()) # True \r\n\r\n# \u534a\u89d2\u8a18\u53f7 \r\nprint(&quot;!&quot;.isalnum()) # False \r\nprint(&quot;!&quot;.isalpha()) # False \r\n\r\n\r\n# \u5168\u89d2\r\nprint(&quot;\u3042&quot;.isalnum()) # True\r\nprint(&quot;\u3042&quot;.isalpha()) # True \r\n\r\n<\/pre>\n<h3>isdigit\/isdecimal\/isnumeric<\/h3>\n<p>\u307e\u305f\u3001\u6570\u5b57\u6587\u5b57\u306e\u5224\u5b9a\u3068\u3057\u3066isdecimal()\u3001isdigit()\u3001isnumeric()\u306e3\u3064\u306e\u6570\u5024\u5224\u5b9a\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u53d6\u308a\u6271\u3046\u6587\u5b57\u306b\u4f9d\u3063\u3066\u306f\u5fae\u5999\u306b\u6319\u52d5\u304c\u7570\u306a\u308a\u307e\u3059\u3002\u5c0f\u6570\u70b9\u3092\u542b\u3080\u6587\u5b57\u306f\u3044\u305a\u308c\u3082\u6570\u5024\u3068\u3057\u3066\u5224\u5b9a\u3055\u308c\u306a\u3044\u305f\u3081\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u307e\u305f\u7b26\u53f7\u4ed8\u304d\u306e\u5834\u5408\u3082\u6570\u5024\u3068\u306f\u5224\u5b9a\u3055\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u305f\u3081\u3001\u6570\u5024\u3078\u306e\u5909\u63db\u53ef\u5426\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u304a\u3059\u3059\u3081\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u306fisdigit\u3001isdecimal\u3001isnumeric\u3092\u4f7f\u7528\u3057\u3066\u6319\u52d5\u3092\u6bd4\u8f03\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u534a\u89d2\u6570\u5b57\r\nprint(&quot;1&quot;.isdigit()) # True\r\nprint(&quot;1&quot;.isdecimal()) # True\r\nprint(&quot;1&quot;.isnumeric()) # True\r\n\r\n# \u534a\u89d2\u6570\u5024(\u7b26\u53f7\u4ed8\u304d)\r\nprint(&quot;0.01&quot;.isdigit()) # False \r\nprint(&quot;0.01&quot;.isdecimal()) # False \r\nprint(&quot;0.01&quot;.isnumeric()) # False \r\n \r\n# \u534a\u89d2\u6570\u5024(\u5c0f\u6570)\r\nprint(&quot;0.01&quot;.isdigit()) # False \r\nprint(&quot;0.01&quot;.isdecimal()) # False \r\nprint(&quot;0.01&quot;.isnumeric()) # False \r\n\r\n# U+0660\u3092\u542b\u3080\u5834\u5408\r\nprint(&quot;0\u066001&quot;.isdigit()) # True \r\nprint(&quot;0\u066001&quot;.isdecimal()) # True \r\nprint(&quot;0\u066001&quot;.isnumeric()) # True \r\n\r\n# \u5168\u89d2\u6570\u5b57\r\nprint(&quot;\uff11&quot;.isdigit()) # True\r\nprint(&quot;\uff11&quot;.isdecimal()) # True\r\nprint(&quot;\uff11&quot;.isnumeric()) # True\r\n\r\n# \u5168\u89d2\u6f22\u6570\u5b57\r\nprint(&quot;\u767e&quot;.isdigit()) # False \r\nprint(&quot;\u767e&quot;.isdecimal()) #  False\r\nprint(&quot;\u767e&quot;.isnumeric()) # True\r\n\r\n# \u5168\u89d2\u30ed\u30fc\u30de\u6570\u5b57\r\nprint(&quot;\u2163&quot;.isdigit()) # False \r\nprint(&quot;\u2163&quot;.isdecimal()) # False \r\nprint(&quot;\u2163&quot;.isnumeric()) # True\r\n\r\n<\/pre>\n<h2>\u88dc\u8db3 \u6587\u5b57\u5217\u306e\u6570\u5b57\u5909\u63db\u53ef\u5426\u306e\u5224\u5b9a<\/h2>\n<p>\u6587\u5b57\u5217\u3092\u6574\u6570\u306b\u5909\u63db\u3059\u308b\u5834\u5408\u306f\u7d44\u8fbc\u307f\u306eint\u95a2\u6570\u3092\u3001\u5c0f\u6570\u306b\u5909\u63db\u3059\u308b\u5834\u5408\u306f\u7d44\u8fbc\u307f\u306efloat\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u6574\u6570\r\ninteger_str = &quot;100&quot;\r\ninteger_num = int(integer_str)\r\nprint(integer_num)\r\n\r\n# \u5c0f\u6570\r\ndecimal_str = &quot;1.55&quot;\r\ndecimal_num = float(decimal_str)\r\nprint(decimal_num)\r\n<\/pre>\n<p>\u6570\u5024\u306b\u5909\u63db\u3067\u304d\u306a\u3044\u4e0d\u6b63\u306a\u6587\u5b57\u5217\u306e\u5834\u5408\u306fValueError\u304c\u9001\u51fa\u3055\u308c\u307e\u3059\u3002\u524d\u8ff0\u306e\u3068\u304a\u308a\u3001\u7b26\u53f7\u3084\u5c0f\u6570\u70b9\u3067\u306fstr\u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u5224\u5225\u3067\u304d\u307e\u305b\u3093\u3002\u81ea\u524d\u3067\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u7528\u3057\u3066\u3082\u826f\u3044\u306e\u3067\u3059\u304c\u3001\u53b3\u5bc6\u306b\u306f\u7b26\u53f7\u3068\u5c0f\u6570\u70b9\u4ee5\u5916\u306b\u6307\u6570\u8868\u8a18\u7b49\u3082\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3067\u3059\u304c\u3001\u307e\u305a\u5909\u63db\u51e6\u7406\u3092\u884c\u3044\u5909\u63db\u306b\u5931\u6557\u3059\u308c\u3070ValueError\u304c\u8d77\u304d\u308b\u305f\u3081\u3001\u3053\u308c\u3092\u5229\u7528\u3059\u308c\u3070\u7b26\u53f7\u4ed8\u304d\u3084\u6307\u6570\u8868\u8a18\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u5224\u5b9a\u3068\u5909\u63db\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef is_float_str(num_str, default=0):\r\n    try:\r\n        return {&quot;is_float&quot;: True ,&quot;val&quot;: float(num_str)}\r\n    except ValueError:\r\n        return {&quot;is_float&quot;: False , &quot;val&quot;: default}\r\n        \r\n\r\nprint(is_float_str(&quot;1.5x&quot;)) # \u5909\u63db\u306b\u5931\u6557{'is_float': False, 'val': 0}\r\nprint(is_float_str(&quot;-1.5&quot;)) # \u5909\u63db\u306b\u6210\u529f{'is_float': True, 'val': -1.5}\r\nprint(is_float_str(&quot;1E16&quot;)) # \u5909\u63db\u306b\u6210\u529f{'is_float': True, 'val': 1e+16}\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3001\u6570\u5024\u3078\u306e\u5909\u63db\u53ef\u5426\u3068\u5909\u63db\u306b\u6210\u529f\u3057\u305f\u5834\u5408\u306f\u305d\u306e\u5024\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001default\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u5909\u63db\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306e\u6587\u5b57\u5217\u306b\u306fis\uff5e\u3068\u3044\u3046\u7a2e\u5225\u306e\u5224\u5225\u7528\u30e1\u30bd\u30c3\u30c9\u304c\u591a\u6570\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u5224\u5b9a\u30e1\u30bd\u30c3\u30c9 Python\u306e\u6587\u5b57\u5217\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6587\u5b57\u5217\u306e\u7a2e\u5225\u306e\u5224\u5b9a\u7528\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u30021\u6587\u5b57\u4ee5\u4e0a\u3067\u306a\u304a\u304b\u3064\u3059\u3079\u3066\u306e\u6587\u5b57\u304c\u6761\u4ef6\u3092...<\/p>\n","protected":false},"author":1,"featured_media":3644,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[75],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/420"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":5,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":3645,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/420\/revisions\/3645"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3644"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}