{"id":194,"date":"2017-01-20T13:41:48","date_gmt":"2017-01-20T04:41:48","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=194"},"modified":"2021-09-12T19:44:58","modified_gmt":"2021-09-12T10:44:58","slug":"str%e6%96%87%e5%ad%97%e5%88%97%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/194","title":{"rendered":"str(\u6587\u5b57\u5217)\u578b"},"content":{"rendered":"<p>Python\u306e\u6587\u5b57\u5217\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u306e\u4e00\u7a2e\u3067\u3001\u6587\u5b57\u5217\u30b7\u30fc\u30b1\u30f3\u30b9\u3068\u547c\u3070\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u57fa\u672c\u7684\u306a\u5185\u5bb9\u306e\u7d39\u4ecb\u306b\u3068\u3069\u3081\u307e\u3059\u3002\u3088\u308a\u8a73\u3057\u3044\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u5185\u5bb9\u306f<a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/category\/entry\/string-entry\">\u6587\u5b57\u5217\u64cd\u4f5c<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u6587\u5b57\u5217\u3068\u521d\u671f\u5316<\/h2>\n<p>Python\u306e\u6587\u5b57\u5217\u306fstr\u578b\u3068\u3044\u3046\u578b\u3067\u6271\u308f\u308c\u307e\u3059\u3002\u4ee5\u964d\u3001str\u578b\u5909\u6570\u3092\u5358\u306b\u6587\u5b57\u5217\u3068\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u6587\u5b57\u5217\u3092\u521d\u671f\u5316\u3059\u308b\u969b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c8\u304b\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c8\u3067\u6587\u5b57\u5217\u3092\u56f2\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext1 = '\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c8\u3067\u56f2\u3080'\r\ntext2 = &quot;\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c8\u3067\u3082OK&quot;\r\n<\/pre>\n<h2>\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9<\/h2>\n<p>\u6539\u884c\u3084\u30bf\u30d6\u306a\u3069\u306e\u7279\u6b8a\u6587\u5b57\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u3068\u3057\u3066\\\u30de\u30fc\u30af\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u30c0\u30d6\u30eb\u30b3\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u304f\u304f\u3063\u305f\u6587\u5b57\u5217\u306e\u5185\u90e8\u3067<\/p>\n<p>\u300c\u5f97\u610f\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306f\"Python\"\u3067\u3059\u3002\u300d<\/p>\n<p>\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;\u5f97\u610f\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306f&quot;Python&quot;\u3067\u3059\u3002&quot;\r\n# SyntaxError: invalid syntax\r\n<\/pre>\n<p>\u5f53\u7136\u306a\u304c\u3089\u3001\u4e0a\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u30a8\u30e9\u30fc\u3068\u306a\u308a\u300cSyntaxError: invalid syntax\u300d\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002\u30c0\u30d6\u30eb\u30b3\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u542b\u3093\u3060\u6587\u5b57\u5217\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;\u5f97\u610f\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306f\\&quot;Python\\&quot;\u3067\u3059\u3002&quot;\r\nprint(text)\r\n<\/pre>\n<p>\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u306b\u3064\u3044\u3066\u7406\u89e3\u3067\u304d\u305f\u3068\u3053\u308d\u3067\u3001\u4ee5\u4e0b\u306b\u4ee3\u8868\u7684\u306a\u3082\u306e\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<table>\n<tr>\n<th>\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9<\/th>\n<th>\u610f\u5473<\/th>\n<\/tr>\n<tr>\n<td>\\t<\/td>\n<td>\u30bf\u30d6<\/td>\n<\/tr>\n<tr>\n<td>\\\\<\/td>\n<td>\\<\/td>\n<\/tr>\n<tr>\n<td>\\'<\/td>\n<td>\u30b7\u30f3\u30b0\u30eb\u30b3\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3<\/td>\n<\/tr>\n<tr>\n<td>\\\"<\/td>\n<td>\u30c0\u30d6\u30eb\u30af\u30b3\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>\u6539\u884c<\/td>\n<\/tr>\n<\/table>\n<h2>raw\u6587\u5b57\u5217<\/h2>\n<p>Python\u306e\u6587\u5b57\u5217\u5b9a\u7fa9\u306e\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u524d\u306br\u3082\u3057\u304f\u306fR\u3092\u8a18\u8ff0\u3059\u308b\u3068raw\u6587\u5b57\u5217\u3068\u547c\u3070\u308c\u308b\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u3067\u4f7f\u7528\u3057\u305f\\\u30de\u30fc\u30af\u3092\u7121\u52b9\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>raw\u6587\u5b57\u5217<\/span><\/div>\nr\"\u6587\u5b57\u5217\"<br \/>\n<\/div>\n<p>raw\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u4f8b\u3048\u3070Windows\u7cfb\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30d1\u30b9\u3092\u8a18\u8ff0\u3059\u308b\u969b\u306b\u30d1\u30b9\u30bb\u30d1\u30ec\u30fc\u30bf\u3068\u30a8\u30b9\u30b1\u30fc\u30d7\u3067\u8a18\u8ff0\u304c\u7169\u96d1\u306b\u306a\u308b\u306e\u3092\u3055\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\npath1 = &quot;C:\\\\work\\\\pywork&quot;\r\nprint(path1)\r\npath2 = r&quot;C:\\work\\pywork&quot;\r\nprint(path2)\r\n<\/pre>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u3067path1\u3068path2\u306f\u540c\u3058\u5185\u5bb9\u3067\u3059\u304c\u3001raw\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3057\u305fpath2\u306e\u307b\u3046\u304c\u30b9\u30c3\u30ad\u30ea\u304b\u3051\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u6587\u5b57\u5217\u306e\u7d50\u5408<\/h2>\n<h3>\u6587\u5b57\u5217\u306e\u7d50\u5408<\/h3>\n<p>\u6587\u5b57\u5217\u540c\u58eb\u3092\u7d50\u5408\u3059\u308b\u5834\u5408\u306f\"+\"\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext1 = '\u4eca\u65e5\u306f'\r\ntext2 = '\u3044\u3044\u5929\u6c17'\r\n\r\ntext3 = text1 + text2\r\n\r\nprint(text3) # \u4eca\u65e5\u306f\u3044\u3044\u5929\u6c17 \u304c\u51fa\u529b\u3055\u308c\u308b\r\n<\/pre>\n<h3>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6587\u5b57\u5217\u8868\u73fe\u3068\u6587\u5b57\u5217\u7d50\u5408<\/h3>\n<p>Python\u306eprint\u6587\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3059\u308b\u3068\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6587\u5b57\u5217\u8868\u73fe\u3092\u5f97\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u3053\u308c\u307e\u3067\u5b66\u7fd2\u3057\u3066\u304d\u305f\u6570\u5024\u3084\u30ea\u30b9\u30c8\u306e\u5024\u3092\u53c2\u7167\u3057\u305f\u3044\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bprint\u6587\u3067\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nnum = 5\r\nprint(num) # 5\r\n\r\nl = [1, 2, 3]\r\nprint(l) # [1, 2, 3]\r\n<\/pre>\n<p>\u3053\u3053\u3067\u6c17\u3092\u3064\u3051\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u3001\u6587\u5b57\u5217\u3068\u3057\u3066\u7d50\u5408\u3059\u308b\u3068TypeError\u304c\u767a\u751f\u3059\u308b\u3001\u3068\u3044\u3046\u70b9\u3067\u3059\u3002\u3088\u304f\u3084\u308a\u304c\u3061\u306a\u30a8\u30e9\u30fc\u304c\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nnum = 5\r\ntext = 'text'\r\n\r\nprint(num) # 5\u304c\u51fa\u529b\u3055\u308c\u308b\r\nprint(text + num) # TypeError\u304c\u767a\u751f\r\n<\/pre>\n<p>\u3053\u3093\u306a\u5834\u5408\u3001\u7d44\u8fbc\u307f\u306estr\u95a2\u6570\u3092\u4f7f\u3046\u3053\u3068\u306b\u3088\u308a\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6587\u5b57\u5217\u8868\u73fe\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u6587\u5b57\u5217\u7d50\u5408\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nnum = 5\r\ntext = 'text'\r\n\r\nprint(num) # 5\u304c\u51fa\u529b\u3055\u308c\u308b\r\nprint(text + str(num)) # text5\r\n<\/pre>\n<p>Python\u306b\u3053\u306a\u308c\u3066\u304d\u3066\u3082\u30c7\u30d0\u30c3\u30b0\u6587\u3084\u30ed\u30b0\u51fa\u529b\u3067\u6bd4\u8f03\u7684\u3088\u304f\u3084\u308a\u304c\u3061\u306a\u30df\u30b9\u3067\u3059\u306e\u3067\u3001\u5bfe\u51e6\u65b9\u6cd5\u306b\u3064\u3044\u3066\u77e5\u3063\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306e\u6587\u5b57\u5217\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u306e\u4e00\u7a2e\u3067\u3001\u6587\u5b57\u5217\u30b7\u30fc\u30b1\u30f3\u30b9\u3068\u547c\u3070\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u57fa\u672c\u7684\u306a\u5185\u5bb9\u306e\u7d39\u4ecb\u306b\u3068\u3069\u3081\u307e\u3059\u3002\u3088\u308a\u8a73\u3057\u3044\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u5185\u5bb9\u306f\u6587\u5b57\u5217\u64cd\u4f5c\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u6587\u5b57\u5217\u3068\u521d\u671f\u5316 Python\u306e\u6587\u5b57\u5217\u306fst...<\/p>\n","protected":false},"author":1,"featured_media":3410,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[48,75],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/194"}],"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=194"}],"version-history":[{"count":8,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":3411,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/194\/revisions\/3411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3410"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}