\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u3063\u305f2\u6b21\u5143\u30ea\u30b9\u30c8\u306e\u4f5c\u6210\u4f8b\u3068\u3057\u3066\u3001\u884c\u756a\u53f7\u3068\u5217\u756a\u53f7\u304c\u540c\u3058\u5834\u5408\u306f\u300c1\u300d\u3001\u7570\u306a\u308b\u5834\u5408\u306f\u300c0\u300d\u306e4\u884c3\u5217\u306e2\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u3092\u6319\u3052\u307e\u3059\u3002<\/p>\n\n\n\n
outList = [[1 if i==j else 0 for j in range(1,4)] for i in range(1,5)]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n[\u5b9f\u884c\u7d50\u679c]<\/p>\n\n\n\n
[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]<\/code><\/pre><\/div>\n\n\n\n\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3048\u30702\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u304c1\u884c\u3067\u6e08\u307f\u307e\u3059\u3002<\/p>\n\n\n\n
\u305d\u308c\u306b\u5bfe\u3057\u3066\u5185\u5305\u8868\u8a18\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306e\u8a18\u8ff0\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
outList = []\nfor i in range(1,5):\n buff = []\n for j in range(1,4):\n if i==j:\n buff += [1]\n else:\n buff += [0]\n outList += [buff]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u5185\u5305\u8868\u8a18\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306f9\u884c\u3082\u8a18\u8ff0\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n
\u3053\u306e\u3088\u3046\u306b\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3048\u3070\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u975e\u5e38\u306b\u7c21\u6f54\u306b\u306a\u308b\u306e\u3067\u3001\u5185\u5305\u8868\u8a18\u3092\u899a\u3048\u3066\u304a\u304f\u30e1\u30ea\u30c3\u30c8\u306f\u5927\u304d\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
\u5185\u5305\u8868\u8a18\u306b\u3088\u308b2\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u306f\u4e00\u898b\u96e3\u3057\u305d\u3046\u306b\u898b\u3048\u307e\u3059\u304c\u30011\u30641\u3064\u5206\u89e3\u3057\u3066\u3044\u3051\u3070\u76f4\u3050\u7406\u89e3\u51fa\u6765\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n
for\u6587\u3001if\u6587\u305d\u308c\u305e\u308c\u306e\u7c21\u5358\u306a\u4f8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n
for\u6587\u306e\u5185\u5305\u8868\u8a18<\/h2>\n\n\n\n
for\u6587\u306e\u5185\u5305\u8868\u8a18\u3092\u89e3\u8aac\u3059\u308b\u305f\u3081\u30010\u304b\u30894\u307e\u3067\u306e\u30ea\u30b9\u30c8\u4f5c\u6210\u4f8b\u3092\u6319\u3052\u307e\u3059\u3002\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u305f\u8a18\u8ff0\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
outList = [i for i in range(5)]<\/code><\/pre><\/div>\n\n\n\n[\u5b9f\u884c\u7d50\u679c]<\/p>\n\n\n\n
[0, 1, 2, 3, 4]<\/code><\/pre><\/div>\n\n\n\n\u3053\u308c\u3092\u5185\u5305\u8868\u8a18\u3092\u4f7f\u308f\u306a\u3044\u8a18\u8ff0\u306b\u3059\u308b\u3068\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
outList = []\nfor i in range(5):\n outList += [i]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u4e21\u8005\u3092\u6bd4\u8f03\u3059\u308b\u3068\u3001\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u305f\u8a18\u8ff0\u306ffor\u6587\u306e\u51e6\u7406\u3092\u300cfor\u300d\u306e\u624b\u524d\u306b\u6301\u3063\u3066\u304d\u305f\u5f62\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n\n\n\n
for\u6587\u306e\u5185\u5305\u8868\u8a18\u306f\u3001\u51e6\u7406\u3092\u300cfor\u300d\u306e\u624b\u524d\u306b\u6301\u3063\u3066\u304f\u308b<\/span><\/strong>\u3068\u899a\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\nif\u6587\u306e\u5185\u5305\u8868\u8a18<\/h2>\n\n\n\n
\u6b21\u306bif\u6587\u306e\u5185\u5305\u8868\u8a18\u3092\u89e3\u8aac\u3059\u308b\u305f\u3081\u3001\u30ea\u30b9\u30c8\u9806\u304c3\u756a\u76ee\u307e\u3067\u306f\u300c0\u300d\u30014\u756a\u76ee\u4ee5\u964d\u306f\u300c1\u300d\u3092\u4ee3\u5165\u3059\u308b\u30ea\u30b9\u30c8\u4f5c\u6210\u4f8b\u3092\u6319\u3052\u307e\u3059\u3002\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u305f\u8a18\u8ff0\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
outList = [1 if i>2 else 0 for i in range(5)]<\/code><\/pre><\/div>\n\n\n\n[\u5b9f\u884c\u7d50\u679c]<\/p>\n\n\n\n
[0, 0, 0, 1, 1]<\/code><\/pre><\/div>\n\n\n\n\u5185\u5305\u8868\u8a18\u3092\u4f7f\u308f\u306a\u3044\u8a18\u8ff0\u306f<\/p>\n\n\n\n
outList = []\nfor i in range(5):\n if i>2:\n outList += [1]\n else:\n outList += [0]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u4e21\u8005\u3092\u6bd4\u8f03\u3059\u308b\u3068\u3001\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u305f\u8a18\u8ff0\u306fif\u6587\u306e\u51e6\u7406\u3092\u300cif\u300d\u306e\u624b\u524d\u306b\u6301\u3063\u3066\u304d\u3066\u3001else\u6587\u306e\u51e6\u7406\u3092\u300celse\u300d\u306e\u5f8c\u308d\u306b\u6301\u3063\u3066\u304d\u305f\u5f62\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
if\u6587\u306e\u5185\u5305\u8868\u8a18\u306f\u3001if\u306e\u51e6\u7406\u3092\u300cif\u300d\u306e\u624b\u524d\u306b\u3001else\u306e\u51e6\u7406\u3092\u300celse\u300d\u306e\u5f8c\u308d\u306b\u6301\u3063\u3066\u304f\u308b<\/span><\/strong>\u3068\u899a\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n\u5185\u5305\u8868\u8a18\u3092\u4f7f\u3063\u305f2\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u306e\u89e3\u8aac<\/h2>\n\n\n\n
for\u6587\u3001if\u6587\u306e\u5185\u5305\u8868\u8a18\u304c\u7406\u89e3\u51fa\u6765\u305f\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u30012\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u306e\u4f8b\u3092\u89e3\u8aac\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n
\u5185\u5305\u8868\u8a18\u3092\u4f7f\u7528\u3057\u306a\u3044\u4f8b\u306f\u4ee5\u4e0b\u3067\u3057\u305f\u306d\u3002<\/p>\n\n\n\n
outList = []\nfor i in range(1,5):\n buff = []\n for j in range(1,4):\n if i==j:\n buff += [1]\n else:\n buff += [0]\n outList += [buff]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u591a\u91cd\u30eb\u30fc\u30d7\u304c\u3042\u308b\u8907\u96d1\u306a\u8868\u8a18\u3067\u3082\u3001\u884c\u306efor\u6587\u3001\u5217\u306efor\u6587\u3001if\u6587\u306b\u5206\u89e3\u3057\u30011\u3064\u305a\u3064\u5185\u5305\u8868\u8a18\u306b\u5909\u66f4\u3057\u3066\u3044\u3051\u3070\u3088\u3044\u3067\u3059\u3002\u307e\u305aif\u6587\u3067\u3059\u3002<\/p>\n\n\n\n
outList = []\nfor i in range(1,5):\n buff = []\n for j in range(1,4):\n buff += [1 if i==j else 0]\n outList += [buff]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u6b21\u306b\u5217\u306efor\u6587\u3092\u5185\u5305\u8868\u8a18\u306b\u5909\u66f4\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n
outList = []\nfor i in range(1,5): \n outList += [[1 if i==j else 0 for j in range(1,4)]]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u6700\u5f8c\u306b\u884c\u306efor\u6587\u3092\u5185\u5305\u8868\u8a18\u306b\u5909\u66f4\u3059\u308b\u3068<\/p>\n\n\n\n
outList = [[1 if i==j else 0 for j in range(1,4)] for i in range(1,5)]\nprint(outList)<\/code><\/pre><\/div>\n\n\n\n\u3053\u306e\u3088\u3046\u306b\u591a\u91cd\u30eb\u30fc\u30d7\u30821\u3064\u305a\u3064\u5206\u89e3\u3057\u3066\u8003\u3048\u308c\u3070\u3001\u5185\u5305\u8868\u8a18\u306b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n
\u307e\u3068\u3081<\/h2>\n\n\n\n
\u4ee5\u4e0a\u30012\u6b21\u5143\u30ea\u30b9\u30c8\u306e\u4f5c\u6210\u3092\u5185\u5305\u8868\u8a18\u3067\u7c21\u6f54\u306b\u66f8\u304f\u65b9\u6cd5\u306e\u89e3\u8aac\u3067\u3057\u305f\u3002<\/p>\n\n\n\n
\u5185\u5305\u8868\u8a18\u3092\u899a\u3048\u3066\u304a\u3051\u3070\u3001\u591a\u91cd\u30eb\u30fc\u30d7\u304c\u3042\u308a\u9577\u304f\u306a\u308a\u304c\u3061\u306a2\u6b21\u5143\u30ea\u30b9\u30c8\u4f5c\u6210\u3082\u7c21\u6f54\u306b\u8a18\u8ff0<\/span><\/strong>\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n\u3053\u3093\u306a\u4fbf\u5229\u306a\u65b9\u6cd5\u306f\u3057\u3063\u304b\u308a\u3068\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n\n\n\n
\u4eca\u56de\u306e\u8a18\u4e8b\u304c\u7686\u3055\u3093\u306ePython\u5b66\u7fd2\u306b\u5f79\u7acb\u3064\u306a\u3089\u5e78\u3044\u3067\u3059\u3002<\/p>\n\n\n\n
\u72ec\u308a\u3067Python\u5b66\u7fd2\u3059\u308b\u306e\u306f\u5927\u5909\u3060\u306a\u3068\u601d\u3046\u65b9\u306f\u3001\u66f8\u7c4d\u3084\u30b9\u30af\u30fc\u30eb\u3092\u6d3b\u7528<\/span><\/strong>\u3059\u308b\u306e\u3082\u624b\u3067\u3059\u3002<\/p>\n\n\n\n