110 search resultsShowing 1~20 results

Stocked
hikurochan

@hikurochan

内包表記

リスト内包表記 l = [] for i in range(10): if i % 2 == 0: l.append(i) print(l) 同じことがリスト内包表記では下記のようになる l =...

2
3
Comment1
hikurochan

@hikurochan

json

import json j = { "employee": [ {"id": 111, "name": "Mike"}, {"id": 222, "name": "Nancy"} ] } pri...

0
1
Comment0
hikurochan

@hikurochan

tempfile

ファイルの入出力のテストに使います。 import tempfile # withを閉じるとファイルは削除されます with tempfile.TemporaryFile(mode='w+') ...

0
1
Comment0
hikurochan

@hikurochan

クラス変数

class T(object): #クラス変数(全てのオブジェクトで共有される words = [] def add_word(self,word): #クラス変数にアクセスするときはselfを...

0
1
Comment0
hikurochan

@hikurochan

クラス

class.py class Person(object): #python3ではobject書かなくても良い def say_something(self): print('hello') p...

0
1
Comment0
hikurochan

@hikurochan

range

for-range.py """ これでも0から9をす出力できるが、面倒 list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in list: print(i...

2
4
Comment0
hikurochan

@hikurochan

None

Noneオブジェクトと比較するときは、==ではなくisを使います。 None.py a = None # 推奨されません if a == None: print("None") # 推奨される書...

0
1
Comment1
hikurochan

@hikurochan

辞書

>>> d = {'x': 10, 'y': 20} >>> d {'x': 10, 'y': 20} >>> d['x'] 10 >...

0
0
Comment0
hikurochan

@hikurochan

タプル

>>> t = (1,2,3,4,1,2) >>> t (1, 2, 3, 4, 1, 2) >>> t[0] = 100 Tracebac...

0
0
Comment0
hikurochan

@hikurochan

値渡しと参照渡し

# 参照渡し i = [1,2,3,4,5] j = i j[0] = 100 #jを書き換えるとiも書き換わる print('j=', j) print('i=', i) x = [1, 2,...

0
1
Comment2
hikurochan

@hikurochan

リストのメソッド

r = [1,2,3,4,5,1,2,3] print(r.index(3)) #3を検索して最初のインデックスを返す print(r.index(3, 3)) #start=3 で検索 pri...

0
2
Comment0

110 search resultsShowing 1~20 results

Qiita is a knowledge sharing service for engineers.

  1. You can follow users and tags
  2. You can stock useful information
  3. You can make edit suggestions for articles
Functions that can be used after logging in