差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
python:language_memo [2015/07/31 10:13] – [文字列を日付型へ変換] 非ログインユーザー | python:language_memo [2019/08/19 07:01] (現在) – ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
====== Python ランゲージ メモ ====== | ====== Python ランゲージ メモ ====== | ||
+ | |||
===== 文字列 ===== | ===== 文字列 ===== | ||
+ | |||
==== 書式編集 ==== | ==== 書式編集 ==== | ||
<code python> | <code python> | ||
行 6: | 行 8: | ||
str = " | str = " | ||
str = " | str = " | ||
+ | |||
+ | " | ||
+ | " | ||
+ | |||
+ | str_val = ' | ||
+ | int_val = 123 | ||
+ | f" | ||
+ | " | ||
+ | |||
+ | int_val = 123456789 | ||
+ | int_val1 = 12345 | ||
+ | f' | ||
+ | ' | ||
+ | |||
+ | pi = 3.14159265358979 | ||
+ | f'pi: {pi: | ||
+ | 'pi: 3.14' | ||
+ | |||
+ | flt_val = 123456789.0123456 | ||
+ | f' | ||
+ | 'float value: 123, | ||
+ | |||
+ | flt_val = 1234.5678 | ||
+ | f' | ||
+ | 'float value: | ||
+ | |||
+ | 'int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:# | ||
+ | 'int: 65536; hex: 0x10000; oct: 0o200000; bin: 0b10000000000000000' | ||
</ | </ | ||
行 47: | 行 77: | ||
文字列を日付型へ変換するには、以下のように記述する。 | 文字列を日付型へ変換するには、以下のように記述する。 | ||
<code python> | <code python> | ||
+ | import datetime | ||
+ | import time | ||
+ | |||
datetime.date(*time.strptime(' | datetime.date(*time.strptime(' | ||
+ | datetime.date(2009, | ||
+ | |||
datetime.datetime(*time.strptime(' | datetime.datetime(*time.strptime(' | ||
+ | datetime.datetime(2009, | ||
+ | |||
</ | </ | ||
上記のコードは、以下のように動作している。 | 上記のコードは、以下のように動作している。 | ||
行 82: | 行 119: | ||
ClsA.method: | ClsA.method: | ||
ClsB.method: | ClsB.method: | ||
+ | </ | ||
+ | |||
+ | ===== 参考文献 ===== | ||
+ | [[https:// | ||
+ | [[https:// | ||