{"id":322,"date":"2018-12-30T15:13:12","date_gmt":"2018-12-30T06:13:12","guid":{"rendered":"https:\/\/www.nblog09.com\/w\/?p=322"},"modified":"2025-09-26T16:02:34","modified_gmt":"2025-09-26T07:02:34","slug":"python-string","status":"publish","type":"post","link":"https:\/\/www.nblog09.com\/w\/2018\/12\/30\/python-string\/","title":{"rendered":"Python\u306e\u6587\u5b57\u5217\u578b(str)\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068\u30e1\u30bd\u30c3\u30c9\u4e00\u89a7\u3068\u30b9\u30e9\u30a4\u30b9\u306e\u65b9\u6cd5"},"content":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u306b\u304a\u3051\u308b<strong>\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u57fa\u672c\u30e1\u30bd\u30c3\u30c9<\/strong>\u3092\u3001\u4f53\u7cfb\u7684\u306b\u89e3\u8aac\u3057\u3066\u3044\u304f\u3002<\/p>\n<h2 class=\"title-border\">Python\u6587\u5b57\u5217\u578b\u306e\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Python\u306e\u6587\u5b57\u5217\u578b\uff08str\uff09\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u6271\u3046\u305f\u3081\u306e\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u578b\u3060\u3002\u6587\u5b57\u5217\u306f<strong>\u30a4\u30df\u30e5\u30fc\u30bf\u30d6\u30eb\uff08\u5909\u66f4\u4e0d\u53ef\u80fd\uff09<\/strong>\u306a\u6027\u8cea\u3092\u6301\u3061\u3001\u4e00\u5ea6\u4f5c\u6210\u3055\u308c\u308b\u3068\u5185\u5bb9\u3092\u76f4\u63a5\u5909\u66f4\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002<\/p>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u5217\u306e\u4f5c\u6210\u65b9\u6cd5<\/h3>\n<p>Python\u3067\u306f\u8907\u6570\u306e\u65b9\u6cd5\u3067\u6587\u5b57\u5217\u3092\u4f5c\u6210\u3067\u304d\u308b\u304c\u3001'\uff08\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c8\uff09\u3042\u308b\u3044\u306f\"(\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c8)\u3067\u56f2\u3046\u306e\u304c\u57fa\u672c\u3060\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\"># \u57fa\u672c\u7684\u306a\u6587\u5b57\u5217\u4f5c\u6210\ns1 = '\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c8'\ns2 = \"\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c8\"\ns3 = '''\u8907\u6570\u884c\u306e\n\u30c6\u30ad\u30b9\u30c8\u3082\n\u6271\u3048\u307e\u3059'''\ns4 = \"\"\"\u3053\u308c\u3082\n\u8907\u6570\u884c\u306e\n\u30c6\u30ad\u30b9\u30c8\"\"\"\n\n# \u6587\u5b57\u5217\u306e\u4e2d\u306b\u5f15\u7528\u7b26\u3092\u542b\u3080\u5834\u5408\nmessage1 = \"\u5f7c\u306f'\u3053\u3093\u306b\u3061\u306f'\u3068\u8a00\u3063\u305f\"\nmessage2 = 'She said \"Hello\" to me'\n<\/code><\/pre>\n<\/div>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30a2\u30af\u30bb\u30b9<\/h3>\n<p>\u6587\u5b57\u5217\u306f\u9806\u5e8f\u304c\u3042\u308b\u305f\u3081\u3001\u89d2\u62ec\u5f27[]\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">s = \"Python\"\nprint(s[0])   # 'P' - \u6700\u521d\u306e\u6587\u5b57\nprint(s[-1])  # 'n' - \u6700\u5f8c\u306e\u6587\u5b57\nprint(s[2])   # 't' - 3\u756a\u76ee\u306e\u6587\u5b57\nprint(len(s)) # 6 - \u6587\u5b57\u5217\u306e\u9577\u3055\n\n# \u6ce8\u610f\uff1a\u6587\u5b57\u5217\u306f\u5909\u66f4\u4e0d\u53ef\u80fd\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u76f4\u63a5\u6307\u5b9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002\n# s[0] = 'p'  # \u3053\u308c\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308b\n<\/code><\/pre>\n<\/div>\n<h2 class=\"title-border\">\u6587\u5b57\u5217\u691c\u7d22\u3068\u78ba\u8a8d\u30e1\u30bd\u30c3\u30c9<\/h2>\n<p>\u6587\u5b57\u5217\u306e\u4e2d\u304b\u3089\u7279\u5b9a\u306e\u90e8\u5206\u3092\u898b\u3064\u3051\u305f\u308a\u3001\u6587\u5b57\u5217\u306e\u6027\u8cea\u3092\u78ba\u8a8d\u3057\u305f\u308a\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u7d39\u4ecb\u3059\u308b\u3002\u3053\u308c\u3089\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u51e6\u7406\u3084\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u51e6\u7406\u3067\u983b\u7e41\u306b\u4f7f\u7528\u3055\u308c\u308b\u3002<\/p>\n<div class=\"sub-item\">\n<h3>\u691c\u7d22\u30e1\u30bd\u30c3\u30c9<\/h3>\n<ul>\n<li>find(substring): \u90e8\u5206\u6587\u5b57\u5217\u306e<strong>\u6700\u521d\u306e\u4f4d\u7f6e\u3092\u8fd4\u3059\uff08\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f-1\uff09<\/strong>\n<li>index(substring): \u90e8\u5206\u6587\u5b57\u5217\u306e<strong>\u6700\u521d\u306e\u4f4d\u7f6e\u3092\u8fd4\u3059\uff08\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u4f8b\u5916\u767a\u751f\uff09<\/strong>\n<li>count(substring): \u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u306e<strong>\u51fa\u73fe\u56de\u6570\u3092\u30ab\u30a6\u30f3\u30c8<\/strong>\n<li>startswith(prefix): \u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u3067<strong>\u59cb\u307e\u308b\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>endswith(suffix): \u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u3067<strong>\u7d42\u308f\u308b\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\">s = \"Python programming\"\n\n# \u90e8\u5206\u6587\u5b57\u5217\u306e\u4f4d\u7f6e\u3092\u691c\u7d22\nprint(s.find(\"pro\"))     # 7 - \u898b\u3064\u304b\u3063\u305f\u4f4d\u7f6e\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\nprint(s.find(\"java\"))    # -1 - \u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\nprint(s.index(\"pro\"))    # 7 - find\u3068\u540c\u69d8\u3060\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u4f8b\u5916\nprint(s.count(\"p\"))      # 1 - \u51fa\u73fe\u56de\u6570\u3092\u30ab\u30a6\u30f3\u30c8\n\n# \u958b\u59cb\u30fb\u7d42\u4e86\u306e\u78ba\u8a8d\nprint(s.startswith(\"Py\"))    # True - \u6307\u5b9a\u6587\u5b57\u5217\u3067\u59cb\u307e\u308b\u304b\nprint(s.endswith(\"ing\"))     # True - \u6307\u5b9a\u6587\u5b57\u5217\u3067\u7d42\u308f\u308b\u304b\n<\/code><\/pre>\n<\/div>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u7a2e\u985e\u306e\u78ba\u8a8d\u30e1\u30bd\u30c3\u30c9<\/h3>\n<ul>\n<li>isdigit(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u6570\u5b57\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>isalpha(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>isalnum(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u307e\u305f\u306f\u6570\u5b57\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>isupper(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u5927\u6587\u5b57\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>islower(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u5c0f\u6587\u5b57\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<li>isspace(): \u3059\u3079\u3066\u306e\u6587\u5b57\u304c<strong>\u7a7a\u767d\u6587\u5b57\u304b\u3069\u3046\u304b<\/strong>\u3092\u5224\u5b9a\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\"># \u6587\u5b57\u306e\u7a2e\u985e\u3092\u78ba\u8a8d\nprint(\"123\".isdigit())       # True - \u3059\u3079\u3066\u6570\u5b57\u304b\nprint(\"abc\".isalpha())       # True - \u3059\u3079\u3066\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u304b\nprint(\"abc123\".isalnum())    # True - \u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u3068\u6570\u5b57\u306e\u307f\u304b\nprint(\"UPPER\".isupper())     # True - \u3059\u3079\u3066\u5927\u6587\u5b57\u304b\nprint(\"lower\".islower())     # True - \u3059\u3079\u3066\u5c0f\u6587\u5b57\u304b\nprint(\"   \".isspace())       # True - \u3059\u3079\u3066\u7a7a\u767d\u6587\u5b57\u304b\n\n# \u5b9f\u7528\u7684\u306a\u4f7f\u7528\u4f8b\nuser_input = input(\"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044: \")\nif user_input.isdigit():\n    number = int(user_input)\n    print(f\"\u5165\u529b\u3055\u308c\u305f\u6570\u5b57\u306f{number}\u3067\u3059\")\nelse:\n    print(\"\u6570\u5b57\u4ee5\u5916\u304c\u5165\u529b\u3055\u308c\u307e\u3057\u305f\")\n<\/code><\/pre>\n<\/div>\n<a href=\"https:\/\/www.udemy.com\/course\/python-python\/?couponCode=20260400_NM_PYTHON\" target=\"_blank\"><div class=\"affiliate-box\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/2025\/09\/Python3.11.png\" alt=\"Python\u8b1b\u5ea7\" class=\"affiliate-img\"><div class=\"affiliate-text\"><h3 class=\"affiliate-title\">\u3010Udemy\u3011Python\u5165\u9580\u8b1b\u5ea7(0\u304b\u3089Python\u306e\u57fa\u790e\u3092\u4f53\u7cfb\u7684\u306b\u5b66\u3093\u3067\u3001\u751f\u6210AI\u3067\u30d0\u30a4\u30d6\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0)<\/h3><p class=\"affiliate-desc\">\u53d7\u8b1b\u751f3000\u4eba\u307b\u3069\u306e\u4eba\u6c17\u8b1b\u5ea7\u3002<strong>Python\u306e\u57fa\u790e\u304b\u3089\u751f\u6210AI\u6d3b\u7528<\/strong>\u307e\u3067\u3092<strong>20\u6642\u9593\u307b\u3069<\/strong>\u3067\u4e00\u6c17\u306b\u5b66\u3073\u307e\u3059\u3002\u696d\u52d9\u3067\u6d3b\u304b\u305b\u308bPython\u306e\u57fa\u790e\u77e5\u8b58\u306f\u3057\u3063\u304b\u308a\u3068\u8eab\u306b\u3064\u304d\u307e\u3059\u3002<\/p><\/div><\/div><\/a>\n<h2 class=\"title-border\">\u6587\u5b57\u5217\u5909\u63db\u30e1\u30bd\u30c3\u30c9<\/h2>\n<p>\u6587\u5b57\u5217\u3092\u52a0\u5de5\u30fb\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3082\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<div class=\"sub-item\">\n<h3>\u5927\u6587\u5b57\u30fb\u5c0f\u6587\u5b57\u5909\u63db<\/h3>\n<ul>\n<li>upper(): \u3059\u3079\u3066\u306e\u6587\u5b57\u3092<strong>\u5927\u6587\u5b57\u306b<\/strong>\u5909\u63db\n<li>lower(): \u3059\u3079\u3066\u306e\u6587\u5b57\u3092<strong>\u5c0f\u6587\u5b57\u306b<\/strong>\u5909\u63db\n<li>capitalize(): <strong>\u6700\u521d\u306e\u6587\u5b57\u306e\u307f<\/strong>\u5927\u6587\u5b57\u306b\u3001\u6b8b\u308a\u3092\u5c0f\u6587\u5b57\u306b\u5909\u63db\n<li>title(): <strong>\u5404\u5358\u8a9e\u306e\u5148\u982d\u6587\u5b57\u3092<\/strong>\u5927\u6587\u5b57\u306b\u5909\u63db\n<li>swapcase(): \u5927\u6587\u5b57\u3068\u5c0f\u6587\u5b57\u3092<strong>\u5165\u308c\u66ff\u3048\u308b<\/strong>\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\">s = \"Python Programming\"\n\n# \u5927\u6587\u5b57\u30fb\u5c0f\u6587\u5b57\u5909\u63db\nprint(s.upper())       # \"PYTHON PROGRAMMING\" - \u3059\u3079\u3066\u5927\u6587\u5b57\nprint(s.lower())       # \"python programming\" - \u3059\u3079\u3066\u5c0f\u6587\u5b57\nprint(s.capitalize())  # \"Python programming\" - \u6700\u521d\u306e\u6587\u5b57\u306e\u307f\u5927\u6587\u5b57\nprint(s.title())       # \"Python Programming\" - \u5404\u5358\u8a9e\u306e\u5148\u982d\u3092\u5927\u6587\u5b57\nprint(s.swapcase())    # \"pYTHON pROGRAMMING\" - \u5927\u6587\u5b57\u3068\u5c0f\u6587\u5b57\u3092\u5165\u308c\u66ff\u3048\n\n# \u5b9f\u7528\u4f8b\uff1a\u30e6\u30fc\u30b6\u30fc\u540d\u306e\u6b63\u898f\u5316\nusername = input(\"\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044: \").strip().lower()\nprint(f\"\u6b63\u898f\u5316\u3055\u308c\u305f\u30e6\u30fc\u30b6\u30fc\u540d: {username}\")\n<\/code><\/pre>\n<\/div>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u5217\u306e\u7f6e\u63db<\/h3>\n<ul>\n<li>replace(old, new, count=None): \u6307\u5b9a\u6587\u5b57\u5217\u3092<strong>\u5225\u306e\u6587\u5b57\u5217\u306b<\/strong>\u7f6e\u63db\uff08count\u3067\u7f6e\u63db\u56de\u6570\u3092\u5236\u9650\u53ef\u80fd\uff09\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\">s = \"Python programming is fun\"\n\n# \u6587\u5b57\u5217\u306e\u7f6e\u63db\nprint(s.replace(\"Python\", \"Java\"))        # \"Java programming is fun\"\nprint(s.replace(\"programming\", \"coding\"))  # \"Python coding is fun\"\nprint(s.replace(\" \", \"_\"))                 # \"Python_programming_is_fun\"\n\n# \u7f6e\u63db\u56de\u6570\u3092\u6307\u5b9a\ntext = \"apple apple apple\"\nprint(text.replace(\"apple\", \"orange\", 2))  # \"orange orange apple\"\n\n# \u5b9f\u7528\u4f8b\uff1a\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u6587\u5b57\u5217\u306e\u51e6\u7406\ntemplate = \"\u3053\u3093\u306b\u3061\u306f\u3001{name}\u3055\u3093\u3002\u4eca\u65e5\u306f{date}\u3067\u3059\u306d\u3002\"\nmessage = template.replace(\"{name}\", \"\u7530\u4e2d\").replace(\"{date}\", \"2024\u5e741\u670815\u65e5\")\nprint(message)  # \u3053\u3093\u306b\u3061\u306f\u3001\u7530\u4e2d\u3055\u3093\u3002\u4eca\u65e5\u306f2024\u5e741\u670815\u65e5\u3067\u3059\u306d\u3002\n<\/code><\/pre>\n<\/div>\n<div class=\"sub-item\">\n<h3>\u7a7a\u767d\u6587\u5b57\u306e\u51e6\u7406<\/h3>\n<p>\u6587\u5b57\u306e\u7a7a\u767d\u3092\u524a\u9664\u3059\u308b\u306e\u306f\u3088\u304f\u7528\u3044\u3089\u308c\u308b\u3002<\/p>\n<ul>\n<li>strip(chars=None): \u6587\u5b57\u5217\u306e<strong>\u4e21\u7aef\u304b\u3089<\/strong>\u6307\u5b9a\u6587\u5b57\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u767d\u6587\u5b57\uff09\u3092\u524a\u9664\n<li>lstrip(chars=None): \u6587\u5b57\u5217\u306e<strong>\u5de6\u7aef\u304b\u3089<\/strong>\u6307\u5b9a\u6587\u5b57\u3092\u524a\u9664\n<li>rstrip(chars=None): \u6587\u5b57\u5217\u306e<strong>\u53f3\u7aef\u304b\u3089<\/strong>\u6307\u5b9a\u6587\u5b57\u3092\u524a\u9664\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\"># \u7a7a\u767d\u306e\u524a\u9664\ntext = \"   Hello World   \"\nprint(f\"'{text.strip()}'\")   # 'Hello World' - \u4e21\u7aef\u306e\u7a7a\u767d\u3092\u524a\u9664\nprint(f\"'{text.lstrip()}'\")  # 'Hello World   ' - \u5de6\u7aef\u306e\u7a7a\u767d\u3092\u524a\u9664\nprint(f\"'{text.rstrip()}'\")  # '   Hello World' - \u53f3\u7aef\u306e\u7a7a\u767d\u3092\u524a\u9664\n\n# \u7279\u5b9a\u306e\u6587\u5b57\u3092\u524a\u9664\nfilename = \"example.txt.backup\"\nprint(filename.rstrip(\".backup\"))  # \"example.txt\"\n\n# \u5b9f\u7528\u4f8b\uff1aCSV\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\ncsv_data = \" apple , banana , orange \"\nitems = [item.strip() for item in csv_data.split(\",\")]\nprint(items)  # ['apple', 'banana', 'orange']\n<\/code><\/pre>\n<\/div>\n<h2 class=\"title-border\">\u6587\u5b57\u5217\u306e\u5206\u5272\u3068\u7d50\u5408<\/h2>\n<p>\u6587\u5b57\u5217\u3092\u5206\u5272\u3057\u3066\u914d\u5217\u306b\u3057\u305f\u308a\u3001\u9006\u306b\u914d\u5217\u3092\u7d50\u5408\u3057\u3066\u6587\u5b57\u5217\u306b\u3057\u305f\u308a\u3059\u308b\u64cd\u4f5c\u306f\u3001\u30c7\u30fc\u30bf\u51e6\u7406\u306e\u57fa\u672c\u7684\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3060\u3002<\/p>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u5217\u306e\u5206\u5272<\/h3>\n<p>\u6587\u5b57\u5217\u3092\u5206\u5272\u3057\u3066\u3001<a href=\"https:\/\/www.nblog09.com\/w\/2018\/12\/31\/python-list\/\">\u5225\u306e\u8a18\u4e8b\u3067<\/a>\u89e3\u8aac\u3057\u3066\u3044\u308b\u30ea\u30b9\u30c8\u578b\u306b\u5909\u63db\u3059\u308b\u3002<\/p>\n<ul>\n<li>split(sep=None, maxsplit=-1): <strong>\u6307\u5b9a\u533a\u5207\u308a\u6587\u5b57\u3067<\/strong>\u6587\u5b57\u5217\u3092\u5206\u5272\u3057\u3066\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\n<li>splitlines(keepends=False): <strong>\u6539\u884c\u6587\u5b57\u3067<\/strong>\u6587\u5b57\u5217\u3092\u5206\u5272\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\">s = \"Python programming language\"\n\n# \u7a7a\u767d\u3067\u5206\u5272\nwords = s.split()\nprint(words)  # ['Python', 'programming', 'language']\n\n# \u6307\u5b9a\u6587\u5b57\u3067\u5206\u5272\nemail = \"user@example.com\"\nparts = email.split(\"@\")\nprint(parts)  # ['user', 'example.com']\n\n# \u5206\u5272\u6570\u3092\u5236\u9650\ntext = \"apple,banana,orange,grape\"\nresult = text.split(\",\", 2)  # \u6700\u59272\u56de\u5206\u5272\nprint(result)  # ['apple', 'banana', 'orange,grape']\n\n# \u884c\u5358\u4f4d\u3067\u306e\u5206\u5272\nmultiline = \"\"\"\u7b2c1\u884c\n\u7b2c2\u884c\n\u7b2c3\u884c\"\"\"\nlines = multiline.splitlines()\nprint(lines)  # ['\u7b2c1\u884c', '\u7b2c2\u884c', '\u7b2c3\u884c']\n<\/code><\/pre>\n<\/div>\n<div class=\"sub-item\">\n<h3>\u6587\u5b57\u5217\u306e\u7d50\u5408<\/h3>\n<p>\u30ea\u30b9\u30c8\u578b\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6587\u5b57\u5217\u578b\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/p>\n<ul>\n<li>join(iterable): \u30ea\u30b9\u30c8\u306a\u3069\u306e\u30a4\u30c6\u30e9\u30d6\u30eb\u3092<strong>\u6307\u5b9a\u533a\u5207\u308a\u6587\u5b57\u3067\u7d50\u5408\u3057\u3066<\/strong>\u6587\u5b57\u5217\u3092\u4f5c\u6210\n<\/ul>\n<pre class=\"line-numbers\"><code class=\"language-python\"># \u30ea\u30b9\u30c8\u3092\u6587\u5b57\u5217\u306b\u7d50\u5408\nfruits = [\"apple\", \"banana\", \"orange\"]\nresult = \"-\".join(fruits)\nprint(result)  # \"apple-banana-orange\"\n\n# \u7a7a\u6587\u5b57\u3067\u7d50\u5408\nchars = [\"P\", \"y\", \"t\", \"h\", \"o\", \"n\"]\nword = \"\".join(chars)\nprint(word)  # \"Python\"\n\n# \u5b9f\u7528\u4f8b\uff1a\u30d1\u30b9\u306e\u7d50\u5408\npath_parts = [\"home\", \"user\", \"documents\", \"file.txt\"]\nfile_path = \"\/\".join(path_parts)\nprint(f\"\/{file_path}\")  # \/home\/user\/documents\/file.txt\n\n# CSV\u30c7\u30fc\u30bf\u306e\u751f\u6210\ndata = [\"\u7530\u4e2d\u592a\u90ce\", \"30\", \"\u6771\u4eac\u90fd\"]\ncsv_line = \",\".join(data)\nprint(csv_line)  # \"\u7530\u4e2d\u592a\u90ce,30,\u6771\u4eac\u90fd\"\n<\/code><\/pre>\n<\/div>\n<div class=\"tips\">join()\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u8907\u6570\u306e\u6587\u5b57\u5217\u3092\u7d50\u5408\u3059\u308b\u969b\u306b<strong>+\u6f14\u7b97\u5b50\u3088\u308a\u3082\u52b9\u7387\u7684<\/strong>\u3060\u3002\u7279\u306b\u5927\u91cf\u306e\u6587\u5b57\u5217\u3092\u7d50\u5408\u3059\u308b\u5834\u5408\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u9055\u3044\u304c\u9855\u8457\u306b\u73fe\u308c\u308b\u3002\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u5f37\u529b\u306a\u30c7\u30fc\u30bf\u51e6\u7406\u304c\u53ef\u80fd\u306b\u306a\u308b\u3002<\/div>\n<h2 class=\"title-border\">\u6587\u5b57\u5217\u30b9\u30e9\u30a4\u30b7\u30f3\u30b0\u306e\u6d3b\u7528<\/h2>\n<p><b>\u6587\u5b57\u5217\u30b9\u30e9\u30a4\u30b7\u30f3\u30b0<\/b>\u306f\u3001\u6587\u5b57\u5217\u306e\u7279\u5b9a\u306e\u90e8\u5206\u3092\u62bd\u51fa\u3059\u308b\u5f37\u529b\u306a\u6a5f\u80fd\u3060\u3002\u57fa\u672c\u69cb\u6587\u306f<strong>\u6587\u5b57\u5217[\u958b\u59cb\u4f4d\u7f6e:\u7d42\u4e86\u4f4d\u7f6e:\u30b9\u30c6\u30c3\u30d7]<\/strong>\u3067\u3001\u69d8\u3005\u306a\u5fdc\u7528\u304c\u53ef\u80fd\u3060\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">text = 'abcdefghij'\n\n# \u57fa\u672c\u7684\u306a\u5207\u308a\u51fa\u3057\nprint(text[1:5])   # 'bcde' - \u30a4\u30f3\u30c7\u30c3\u30af\u30b91\u304b\u30894\u307e\u3067\nprint(text[:3])    # 'abc' - \u6700\u521d\u304b\u30893\u6587\u5b57\nprint(text[3:])    # 'defghij' - 4\u6587\u5b57\u76ee\u304b\u3089\u6700\u5f8c\u307e\u3067\nprint(text[:])     # 'abcdefghij' - \u5168\u4f53\u3092\u30b3\u30d4\u30fc\n\n# \u30b9\u30c6\u30c3\u30d7\u3092\u4f7f\u3063\u305f\u4f8b\nprint(text[::2])   # 'acegi' - 2\u6587\u5b57\u304a\u304d\u306b\u53d6\u5f97\nprint(text[1::3])  # 'beh' - \u30a4\u30f3\u30c7\u30c3\u30af\u30b91\u304b\u30893\u6587\u5b57\u304a\u304d\nprint(text[::-1])  # 'jihgfedcba' - \u9006\u9806\n\n# \u5b9f\u7528\u4f8b\uff1a\u6587\u5b57\u5217\u306e\u90e8\u5206\u62bd\u51fa\nphone = \"090-1234-5678\"\narea_code = phone[:3]      # \"090\"\nmiddle = phone[4:8]        # \"1234\"\nlast = phone[9:]           # \"5678\"\nprint(f\"\u30a8\u30ea\u30a2\u30b3\u30fc\u30c9: {area_code}, \u4e2d\u9593: {middle}, \u672b\u5c3e: {last}\")\n\n# \u30d5\u30a1\u30a4\u30eb\u540d\u3068\u62e1\u5f35\u5b50\u306e\u5206\u96e2\nfilename = \"document.pdf\"\nname = filename[:-4]       # \"document\"\nextension = filename[-4:]  # \".pdf\"\nprint(f\"\u30d5\u30a1\u30a4\u30eb\u540d: {name}, \u62e1\u5f35\u5b50: {extension}\")\n<\/code><\/pre>\n<a href=\"https:\/\/www.udemy.com\/course\/python-python\/?couponCode=20260400_NM_PYTHON\" target=\"_blank\"><div class=\"affiliate-box\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/2025\/09\/Python3.11.png\" alt=\"Python\u8b1b\u5ea7\" class=\"affiliate-img\"><div class=\"affiliate-text\"><h3 class=\"affiliate-title\">\u3010Udemy\u3011Python\u5165\u9580\u8b1b\u5ea7(0\u304b\u3089Python\u306e\u57fa\u790e\u3092\u4f53\u7cfb\u7684\u306b\u5b66\u3093\u3067\u3001\u751f\u6210AI\u3067\u30d0\u30a4\u30d6\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0)<\/h3><p class=\"affiliate-desc\">\u53d7\u8b1b\u751f3000\u4eba\u307b\u3069\u306e\u4eba\u6c17\u8b1b\u5ea7\u3002<strong>Python\u306e\u57fa\u790e\u304b\u3089\u751f\u6210AI\u6d3b\u7528<\/strong>\u307e\u3067\u3092<strong>20\u6642\u9593\u307b\u3069<\/strong>\u3067\u4e00\u6c17\u306b\u5b66\u3073\u307e\u3059\u3002\u696d\u52d9\u3067\u6d3b\u304b\u305b\u308bPython\u306e\u57fa\u790e\u77e5\u8b58\u306f\u3057\u3063\u304b\u308a\u3068\u8eab\u306b\u3064\u304d\u307e\u3059\u3002<\/p><\/div><\/div><\/a>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u306b\u304a\u3051\u308b\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u57fa\u672c\u30e1\u30bd\u30c3\u30c9\u3092\u3001\u4f53\u7cfb\u7684\u306b\u89e3\u8aac\u3057\u3066\u3044\u304f\u3002 Python\u6587\u5b57\u5217\u578b\u306e\u57fa\u672c\u6982\u5ff5 Python\u306e\u6587\u5b57\u5217\u578b\uff08str\uff09\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u6271\u3046\u305f\u3081\u306e\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u578b\u3060\u3002\u6587\u5b57\u5217\u306f\u30a4\u30df\u30e5\u30fc\u30bf\u30d6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5048,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uag_custom_page_level_css":"","_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[9,219],"tags":[14,60,59],"class_list":{"0":"post-322","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-it-programming","9":"tag-python","10":"tag-string","11":"tag-59","12":"entry"},"uagb_featured_image_src":{"full":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4.png",812,577,false],"thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-150x150.png",150,150,true],"medium":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-300x213.png",300,213,true],"medium_large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-768x546.png",768,546,true],"large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4.png",812,577,false],"1536x1536":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4.png",812,577,false],"2048x2048":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4.png",812,577,false],"home-middle":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-630x350.png",630,350,true],"home-top":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-750x420.png",750,420,true],"sidebar-thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/Python-4-100x100.png",100,100,true]},"uagb_author_info":{"display_name":"9nmatsumoto","author_link":"https:\/\/www.nblog09.com\/w\/author\/9nmatsumoto\/"},"uagb_comment_info":1,"uagb_excerpt":"\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u306b\u304a\u3051\u308b\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u57fa\u672c\u30e1\u30bd\u30c3\u30c9\u3092\u3001\u4f53\u7cfb\u7684\u306b\u89e3\u8aac\u3057\u3066\u3044\u304f\u3002 Python\u6587\u5b57\u5217\u578b\u306e\u57fa&hellip;","_links":{"self":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":48,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":4983,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/322\/revisions\/4983"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media\/5048"}],"wp:attachment":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}