erg/doc/JA/migration_from_py.md
Shunsuke Shibayama 96132b20f6 initial commit
2022-08-10 23:02:27 +09:00

504 B

PythonからErgへの移行に関してのTips

文字列をint等に変換したい

Strクラスのparseメソッドを使用してください。これはResult型を返します。

s: str
i: int = int(s)
s: Str
res: Result(Int, IntParseError) = s.parse Int
i: Int = res.unwrap()
f: Result(Float, FloatParseError) = s.parse Float

try_fromメソッドも使えます。

s: Str
i: Int = Int.try_from(s).unwrap()
f: Float = Float.try_from(s).unwrap()