Stringの基本
他の型をStringに変換する。
a = 100
b = 3.14
c = str(a) + \'/\' + str(b)
print(c) # 100/3.14
スライスで参照できる。
a = \"hogehoge\"
print(a[3:5]) # eh
Stringのmethod達
Stringは更新不能。method達は自分自身を破壊しない。
戻り値として新しいStringオブジェクトが戻るのみ。
大文字小文字,数値アルファベットの判定はUnicode標準に従う。
# coding: utf-8
# Your code here!
print(\"Hogehoge\".capitalize()) # Hogehoge
print(\"AiUeO\".casefold()) # aiueo
print(\"hoge\".center(10,\'-\')) # ---hoge---
print(\"hogehoge\".count(\'h\')) # 2
print(\"hogehoge\".encode()) # b\'hogehoge\'
print(\"hogehoge\".endswith(\'hoge\')) # True
print(\"hoge\".find(\"ge\")) # 2
print(\"{0} is {1}\".format(\"hoge\",\"fuga\")) # hoge is fuga
print(\"hogehoge\".index(\"geh\"))
print(\"hoge\".isalnum()) # True
print(\"1234\".isalnum()) # True
print(\"()\".isalnum()) # False
print(\"hoge\".isalpha()) # True
print(\"1234\".isalpha()) # False
print(\"1234\".isdecimal()) # True
print(\"12ab\".isdecimal()) # False
print(\"hoge\".isidentifier()) # True
print(\"3ab\".isidentifier()) # Flase
print(\"Hoge\".islower()) # False
print(\"hoge\".islower()) # True
print(\"1234\".isnumeric()) # True
print(\"12ab\".isnumeric()) # False
print(\"t\".isprintable()) # False
print(\"hoge \".isspace()) # False
print(\" \".isspace()) # True
print(\"hoge\".istitle()) # False
print(\"This Is My Hoge\".istitle()) # True
print(\"--\".join([\'1\',\'2\',\'3\',\'4\'])) # 1--2--3--4
print(\"\".join([\'spam\',\'ham\',\'egg\'])) # spamhamegg
print(\"hoge\".ljust(10,\'*\')) # hoge******
print(\"This is hoge\".lower()) # this is hoge
print(\" hoge \".lstrip()) # hoge
print(\"hoge1 hoge2 hoge3\".replace(\"hoge1\",\"fuga1\")) # fuga1 hoge2 hoge3
print(\"12345678\".rfind(\'6\')) # 5
print(\"12345678\".rindex(\'6\')) # 5
print(\"hoge\".rjust(10,\'*\')) # ******hoge
print(\"hoge/fuga\".rpartition(\'/\')) # (\'hoge\', \'/\', \'fuga\')
print(\"hoge*fuga\".rpartition(\'/\')) # (\'\', \'\', \'hoge*fuga\')
print(\"hoge fuga hoge\".rsplit()) # [\'hoge\', \'fuga\', \'hoge\']
print(\"hoge \".rstrip()) # hoge
print(\"hoget\".rstrip()) # hoge
print(\"hoge hoge hoge\".split()) # [\'hoge\', \'hoge\', \'hoge\']
print(\"hoge1rhoge2nhoge3rn\".splitlines()) # [\'hoge1\', \'hoge2\', \'hoge3\']
print(\"hoge1rhoge2nhoge3rn\".splitlines(keepends=True)) # [\'hoge1r\', \'hoge2n\', \'hoge3rn\']
print(\"aiueokakikukeko\".startswith(\"aiueo\")) # True
print(\" hoge \".strip()) # hoge
print(\"AiUeO\".swapcase()) # aIuEo
print(\"hoge hoge hoge\".title()) # Hoge Hoge Hoge
print(\"hogehgoehgoe\".upper()) # HOGEHGOEHGOE
print(\"hoge\".zfill(10)) # 000000hoge
print(\"-foo\".zfill(10)) # -000000foo