Skip to content

Add ljust and rjust methods to str built-in type#3502

Merged
chrisnovakovic merged 1 commit intothought-machine:masterfrom
chrisnovakovic:str-just
Mar 23, 2026
Merged

Add ljust and rjust methods to str built-in type#3502
chrisnovakovic merged 1 commit intothought-machine:masterfrom
chrisnovakovic:str-just

Conversation

@chrisnovakovic
Copy link
Copy Markdown
Contributor

str.ljust(width[, fillchar])
str.rjust(width[, fillchar])

These methods are equivalent to their Python namesakes: they return a copy of the string left-padded or right-padded with the character given by fillchar until it is width characters long. fillchar defaults to ' ' (i.e. a space).

```
str.ljust(width[, fillchar])
str.rjust(width[, fillchar])
```

These methods are equivalent to their Python namesakes: they return a
copy of the string left-padded or right-padded with the character given
by `fillchar` until it is `width` characters long. `fillchar` defaults
to `' '` (i.e. a space).
- returns a copy of this string left-padded with the character given
in <code class="code">fillchar</code> (or the default <code class="code"
>' '</code> if no value is given) until it is <code class="code"
>width</code> characters long.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth declaring here that this is done based on how Go counts characters(/runes)? Or are we happy to leave the "how long is a (piece of) string" nonsense unsaid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's best left unsaid for now, because I'm pretty sure string length operations are inconsistent in ASP and I'd rather people not draw inferences based on statements made in one part of the documentation that are omitted in others. I don't think it's the highest-priority task, but we should probably go through the language and make sure length operations on strings are all character-wise, not byte-wise, as they are in Python.

@chrisnovakovic chrisnovakovic merged commit 94c7f7a into thought-machine:master Mar 23, 2026
13 checks passed
@chrisnovakovic chrisnovakovic deleted the str-just branch March 23, 2026 15:50
DuBento pushed a commit to DuBento/please that referenced this pull request Mar 27, 2026
…ne#3502)

```
str.ljust(width[, fillchar])
str.rjust(width[, fillchar])
```

These methods are equivalent to their Python namesakes: they return a
copy of the string left-padded or right-padded with the character given
by `fillchar` until it is `width` characters long. `fillchar` defaults
to `' '` (i.e. a space).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants