diff options
author | brandjon <brandjon@google.com> | 2018-03-26 12:41:12 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-26 12:42:52 -0700 |
commit | 7a45873dcdebc3e78cc7f26402d533ef9101106b (patch) | |
tree | 0c3674d35c27654161d54020239e56cb021d8417 /site/docs/skylark | |
parent | 61b40750f733d8fb47d50de6965ddf7a3f2dbe66 (diff) |
Fix incorrect int() example
Also add tests for leading "+" in int(<string>) form.
RELNOTES: None
PiperOrigin-RevId: 190507678
Diffstat (limited to 'site/docs/skylark')
-rw-r--r-- | site/docs/skylark/spec.md | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/site/docs/skylark/spec.md b/site/docs/skylark/spec.md index 53c0a5d482..5eedb45dfc 100644 --- a/site/docs/skylark/spec.md +++ b/site/docs/skylark/spec.md @@ -249,7 +249,7 @@ else: The Skylark integer type represents integers. Its [type](#type) is `"int"`. Integers may be positive or negative. The precision is implementation-dependent. -It is a dynamic error if a result is outside that the supported range. +It is a dynamic error if a result is outside the supported range. Integers are totally ordered; comparisons follow mathematical tradition. @@ -2327,12 +2327,15 @@ implies `hash(x) == hash(y)`. `int(x[, base])` interprets its argument as an integer. -If x is an `int`, the result is x. -If x is a `bool`, the result is 0 for `False` or 1 for `True`. +If `x` is an `int`, the result is `x`. +If `x` is a `bool`, the result is 0 for `False` or 1 for `True`. -If x is a string, it is interpreted as an integer using the base argument -(default is `10`). If base is `0`, x is interpreted like an integer literal, the -base being inferred from an optional base prefix (for example `0o` or `0x`). +If `x` is a string, it is interpreted as a sequence of digits in the specified +base, decimal by default. If `base` is zero, `x` is interpreted like an integer +literal, the base being inferred from an optional base marker such as `0b`, +`0o`, or `0x` preceding the first digit. These markers may also be used if +`base` is the corresponding base. Irrespective of base, the string may start +with an optional `+` or `-` sign indicating the sign of the result. ```python int("21") # 21 |