hbutils.string.plural
- Overview:
Useful utilities for pluralizing and singularizing words. This module provides convenient functions to convert words between singular and plural forms, and to format words with their counts in grammatically correct forms.
plural_form
- hbutils.string.plural.plural_form(word: str) str[source]
Get the pluralized form of the given word.
The same as
hbutils.string.inflection.pluralize().- Parameters:
word (str) – The given word to be pluralized.
- Returns:
Pluralized word.
- Return type:
str
- Examples::
>>> from hbutils.string import plural_form >>> plural_form('it') 'they' >>> plural_form('word') 'words' >>> plural_form('woman') 'women'
singular_form
- hbutils.string.plural.singular_form(word: str) str[source]
Get the singular form of the given word.
The same as
hbutils.string.inflection.singularize().- Parameters:
word (str) – The given word to be singularized.
- Returns:
Singular form of word.
- Return type:
str
- Examples::
>>> from hbutils.string import singular_form >>> singular_form('they') 'it' >>> singular_form('it') 'it' >>> singular_form('women') 'woman' >>> singular_form('words') 'word' >>> singular_form('themselves') 'itself'
plural_word
- hbutils.string.plural.plural_word(count: int, word: str) str[source]
Get plural form of the whole word, with the number before the word.
This function formats a word with its count in a grammatically correct way. If the count is 1, the singular form is used; otherwise, the plural form is used.
- Parameters:
count (int) – Count of the word, should be a non-negative integer.
word (str) – Word to be pluralized.
- Returns:
Pluralized word with the number.
- Return type:
str
- Examples::
>>> from hbutils.string import plural_word >>> plural_word(0, 'word') '0 words' >>> plural_word(1, 'word') '1 word' >>> plural_word(2, 'word') '2 words' >>> plural_word(20, 'word') '20 words' >>> plural_word(233, 'word') '233 words'