mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +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()