mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
1,006 B
1,006 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()