{"id":488,"date":"2017-01-22T23:10:07","date_gmt":"2017-01-22T14:10:07","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=488"},"modified":"2018-01-15T23:37:51","modified_gmt":"2018-01-15T14:37:51","slug":"%e3%82%b7%e3%83%bc%e3%82%b1%e3%83%b3%e3%82%b9%e5%9e%8b%e5%85%b1%e9%80%9a%e6%bc%94%e7%ae%97","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/488","title":{"rendered":"\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u5171\u901a\u51e6\u7406"},"content":{"rendered":"<h2>\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u5171\u901a\u51e6\u7406<\/h2>\n<p>\u30ea\u30b9\u30c8\u3001\u30bf\u30d7\u30eb\u3001\u6587\u5b57\u5217\u7b49\u3001\u3069\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u306b\u3082\u4f7f\u7528\u3067\u304d\u308b\u5171\u901a\u7684\u306e\u6f14\u7b97\u3084\u95a2\u6570\u304c\u3042\u308a\u307e\u3059\u3002\u3059\u3067\u306b\u8aac\u660e\u3057\u305f\u3082\u306e\u3082\u542b\u307e\u308c\u307e\u3059\u304c\u3001\u5fa9\u7fd2\u3082\u517c\u306d\u3066\u307e\u3068\u3081\u3066\u6574\u7406\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u6f14\u7b97\u3084\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u6f14\u7b97<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>x in s<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306b\u8981\u7d20x\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u306bTrue\u3092\u8fd4\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td>x not in s<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306b\u8981\u7d20x\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306bTrue\u3092\u8fd4\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td>s + t<\/td>\n<td>2\u3064\u306e\u30b7\u30fc\u30b1\u30f3\u30b9s\u3068t\u3092\u7d50\u5408\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s * n \u307e\u305f\u306f n * s<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u540c\u58eb\u3092n\u56de\u7d50\u5408\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s[i]<\/td>\n<td>0\u59cb\u307e\u308a\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u30b7\u30fc\u30b1\u30f3\u30b9s\u306ei\u756a\u76ee\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s[i:j]<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306ei\u756a\u76ee\u304b\u3089j\u756a\u76ee\u307e\u3067\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s[i:j:k]<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306ei\u756a\u76ee\u304b\u3089j\u756a\u76ee\u307e\u3067\u306ek\u6bce\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>len(s)<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306e\u9577\u3055(=\u8981\u7d20\u6570)\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>min(s)<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306e\u6700\u5c0f\u306e\u8981\u7d20\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>max(s)<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306e\u6700\u5927\u306e\u8981\u7d20\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s.index(x)<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306e\u4e2d\u3067\u8981\u7d20x\u304c\u6700\u521d\u306b\u51fa\u73fe\u3059\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>s.count(x)<\/td>\n<td>\u30b7\u30fc\u30b1\u30f3\u30b9s\u306e\u4e2d\u3067\u8981\u7d20x\u304c\u51fa\u73fe\u3059\u308b\u56de\u6570\u3092\u8fd4\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5171\u901a\u51e6\u7406\u306e\u89e3\u8aac<\/h2>\n<p>\u4ee5\u4e0b\u3001\u3088\u304f\u4f7f\u3046\u3082\u306e\u3092\u4e2d\u5fc3\u306b\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3>\u5305\u542b\u5224\u5b9a(in\u3001not in)<\/h3>\n<p>\u30b7\u30fc\u30b1\u30f3\u30b9s\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8x\u304c\u8981\u7d20\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\u306b\u306fx in s\u3068\u66f8\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\u306b\u306fx not in x\u3068\u66f8\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nlist_data = ['a', 'b', 'c', 'd']\r\n\r\n# \u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\r\nb1 = 'a' in list_data # \u6587\u5b57\u5217'a'\u304c\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\r\nprint(b1) # True\r\n\r\nb2 = 'x' in list_data # \u6587\u5b57\u5217'x'\u304c\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\r\nprint(b2) # False \r\n\r\n# \u542b\u307e\u308c\u3066\u3044\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\r\nb3 = 'a' not in list_data # \u6587\u5b57\u5217'a'\u304c\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\r\nprint(b3) # False \r\n\r\nb4 = 'x' not in list_data # \u6587\u5b57\u5217'x'\u304c\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\r\nprint(b4) # True \r\n<\/pre>\n<h3>\u7d50\u5408(+\u3001*)<\/h3>\n<p>+\u6f14\u7b97\u5b50\u3067\u30b7\u30fc\u30b1\u30f3\u30b9\u540c\u58eb\u3092\u7d50\u5408\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001*\u6f14\u7b97\u5b50\u3067\u6307\u5b9a\u56de\u6570\u5206\u7d50\u5408\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nlist_data1 = ['a', 'b', 'c']\r\nlist_data2 = ['d', 'e', 'f']\r\n\r\n# \u30ea\u30b9\u30c8\u306e\u7d50\u5408\r\nnew_list = list_data1 + list_data2\r\nprint(new_list) # ['a', 'b', 'c', 'd', 'e', 'f']\r\n\r\n# \u7d50\u5408\u306e\u7e70\u308a\u8fd4\u3057\r\nnew_list = list_data1 * 3 # list_data1 + list_data1 + list_data1\u3068\u540c\u3058\r\nprint(new_list) # ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']\r\n<\/pre>\n<h3>\u30b9\u30e9\u30a4\u30b9\u6587<\/h3>\n<p><a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/134\">\u30ea\u30b9\u30c8\u578b\u306e\u30b9\u30e9\u30a4\u30b9\u6587<\/a>\u306f\u65e2\u306b\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001\u6587\u5b57\u5217\u3082\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u306a\u306e\u3067\u540c\u69d8\u306e\u64cd\u4f5c\u304c\u53ef\u80fd\u3067\u3059\u3002\u6587\u5b57\u5217\u3067\u306e\u30b9\u30e9\u30a4\u30b9\u6587\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;ABCDEFG&quot;\r\n\r\n# 0\u756a\u76ee\u304b\u30892\u756a\u76ee\u306e\u624b\u524d\u307e\u3067 \r\nprint(text[0:2]) # AB\r\n\r\n# \u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u7701\u7565\r\nprint(text[:2]) # AB\r\n\r\n# 2\u756a\u76ee\u304b\u3089\u6700\u5f8c\u307e\u3067\r\nprint(text[2:7]) # CDEFG\r\n\r\n# \u6700\u5f8c\u3092\u7701\u7565 \r\nprint(text[2:]) # CDEFG\r\n\r\n# 1\u3064\u3068\u3070\u3057\u3067\r\nprint(text[0:7:2]) # ACEG\r\n<\/pre>\n<p>\u30ea\u30b9\u30c8\u306e\u6642\u3068\u540c\u69d8\u306b\u30b9\u30e9\u30a4\u30b9\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u8981\u7d20\u6570<\/h3>\n<p>len\u95a2\u6570\u3067\u8981\u7d20\u6570\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30ea\u30b9\u30c8\u3001\u30bf\u30d7\u30eb\u3001\u6587\u5b57\u5217\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u30ea\u30b9\u30c8\u306e\u5834\u5408\r\nl = [1, 2, 3]\r\nprint(len(l)) # 3\r\n\r\n# \u30bf\u30d7\u30eb\u306e\u5834\u5408\r\nt = ('a', 'b', 'c', 'd')\r\nprint(len(t)) # 4 \r\n\r\n# \u6587\u5b57\u5217\u306e\u5834\u5408\r\ntext = &quot;abcdefg&quot;\r\nprint(len(text)) # 7\r\n<\/pre>\n<h3>\u6700\u521d\u306b\u51fa\u73fe\u3059\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/h3>\n<p>index\u30e1\u30bd\u30c3\u30c9\u3067\u6307\u5b9a\u3057\u305f\u8981\u7d20\u304c\u4f55\u756a\u76ee\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u5b58\u5728\u3059\u308b\u306e\u304b\u3001\u51fa\u73fe\u3059\u308b\u6700\u521d\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u306a\u304a\u3001\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306fValueError\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd']\r\n\r\nprint(l.index('c')) # 2\r\nprint(l.index('x')) # ValueError: 'x' is not in list\r\n<\/pre>\n<p>\u4ee5\u4e0b\u3001\u6587\u5b57\u5217\u306e\u5834\u5408\u3067\u3059\u3002\u542b\u307e\u308c\u308b\u6587\u5b57\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u90e8\u5206\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;abcefg&quot;\r\nprint(text.index('b')) # 1\r\nprint(text.index('ef')) # 3 \r\nprint(text.index('x')) # ValueError: substring not found\r\n<\/pre>\n<h3>\u51fa\u73fe\u3059\u308b\u56de\u6570<\/h3>\n<p>count\u30e1\u30bd\u30c3\u30c9\u3067\u51fa\u73fe\u3059\u308b\u56de\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;abcefg abcdefg&quot;\r\nprint(text.count('b')) # 2\r\nprint(text.count('ef')) # 2 \r\nprint(text.count('x')) # 0 \r\n<\/pre>\n<h2>\u53c2\u8003\u6587\u732e<\/h2>\n<p><a href=\"http:\/\/docs.python.jp\/3\/library\/stdtypes.html#common-sequence-operations\">\u516c\u5f0f 4.6.1. \u5171\u901a\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u6f14\u7b97<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u5171\u901a\u51e6\u7406 \u30ea\u30b9\u30c8\u3001\u30bf\u30d7\u30eb\u3001\u6587\u5b57\u5217\u7b49\u3001\u3069\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u306b\u3082\u4f7f\u7528\u3067\u304d\u308b\u5171\u901a\u7684\u306e\u6f14\u7b97\u3084\u95a2\u6570\u304c\u3042\u308a\u307e\u3059\u3002\u3059\u3067\u306b\u8aac\u660e\u3057\u305f\u3082\u306e\u3082\u542b\u307e\u308c\u307e\u3059\u304c\u3001\u5fa9\u7fd2\u3082\u517c\u306d\u3066\u307e\u3068\u3081\u3066\u6574\u7406\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u6f14\u7b97\u3084\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e...<\/p>\n","protected":false},"author":1,"featured_media":3392,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[214,48,75],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/488"}],"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=488"}],"version-history":[{"count":12,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/488\/revisions"}],"predecessor-version":[{"id":509,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/488\/revisions\/509"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3392"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}