Top/Lang/Python

目次

基本文法

関数

λ式

値の扱い

組み込み型

bool 型

True / False

文字列

find() / rfind()

str_val.find(<検索したい文字列>, [開始インデックス], [終了インデックス] );

index() / rindex()

str_val.index(<検索したい文字列>, [開始インデックス], [終了インデックス] );

endwith()

str_val.endwith(<検索したい文字列>, [開始インデックス], [終了インデックス] );

startwidth()

str_val.startwidth(<検索したい文字列>, [開始インデックス], [終了インデックス] );

split() / rsplit()

str_val.split( [区切り文字], [分割数] );

join()

strip()

upper()

lower()

ljust()

文字のフォーマット

置換

ソート

sort()

revers()

remove()

append()

extend()

pop()

index()

リスト / list

リストの定義

スライス

リストの演算

a = [ 0, 1, 2 ]
b = [ 5, 6, 7 ]
c = a + b
print c
実行結果 -----------------------
[0, 1, 2, 5, 6, 7]

要素の追加

リストの掛け算

リスト要素の書き換え

要素の削除

リスト要素の検索

リストに存在するかどうかを調べる

リストの何番目の index にあるかを調べる

min / max

sort

set 型

dictionary

フロー制御

if

s = "snowsdutyrytrctyrhandwerwre";
if "hand" in s:  # 文字列の要素を検索
    print( "hand is found!" );

for

書式

for i in range(10, 21);
    # 処理...

range()

class

class 定義

class <class-name>:
    def __init__(self):    # 初期化メソッド
        self.value = 0;
        print( "Initialize done..." );

    def hoge(self, fuga):
        ...

演算子の定義

class CHoge:
    def __init__(self):
        self.x = 0;
        self.y = 0;

    # + 演算子の定義
    def __add__(self, other):
         return CHoge( self.x + other.x, self.y + other.y );

各種演算子を定義する特別関数一覧

OperatorSpecial method
self + other__add__(self, other)
self - other__sub__(self, other)
self * other__mul__(self, other)
self / other__div__(self, other) or __truediv__(self,other) if __future__.division is active.
self // other__floordiv__(self, other)
self % other__mod__(self, other)
divmod(self,other)__divmod__(self, other)
self ** other__pow__(self, other)
self & other__and__(self, other)
self ^ other__xor__(self, other)
self | other__or__(self, other)
self << other__lshift__(self, other)
self >> other__rshift__(self, other)
bool(self)__nonzero__(self) (used in boolean testing)
-self__neg__(self)
+self__pos__(self)
abs(self)__abs__(self)
˜self__invert__(self) (bitwise)
self += other__iadd__(self, other)
self -= other__isub__(self, other)
self *= other__imul__(self, other)
self /= other__idiv__(self, other) or __itruediv__(self,other) if __future__.division is in effect.
self //= other__ifloordiv__(self, other)
self %= other__imod__(self, other)
self **= other__ipow__(self, other)
self &= other__iand__(self, other)
self ^= other__ixor__(self, other)
self |= other__ior__(self, other)
self <<= other__ilshift__(self, other)
self >>= other__irshift__(self, other)

Link

all

on MacOSX

on Windows


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS