Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8775d8b

Browse files
committed
Added capitalize() and capwords().
1 parent 2e1beea commit 8775d8b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/string.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ def translate(s, table):
262262
res = res + table[ord(c)]
263263
return res
264264

265+
# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
266+
def capitalize(s):
267+
return upper(s[:1]) + lower(s[1:])
268+
269+
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
270+
# See also regsub.capwords().
271+
def capwords(s):
272+
return join(map(capitalize, split(s)))
273+
274+
265275
# Try importing optional built-in module "strop" -- if it exists,
266276
# it redefines some string operations that are 100-1000 times faster.
267277
# It also defines values for whitespace, lowercase and uppercase

Lib/stringold.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ def translate(s, table):
262262
res = res + table[ord(c)]
263263
return res
264264

265+
# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
266+
def capitalize(s):
267+
return upper(s[:1]) + lower(s[1:])
268+
269+
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
270+
# See also regsub.capwords().
271+
def capwords(s):
272+
return join(map(capitalize, split(s)))
273+
274+
265275
# Try importing optional built-in module "strop" -- if it exists,
266276
# it redefines some string operations that are 100-1000 times faster.
267277
# It also defines values for whitespace, lowercase and uppercase

0 commit comments

Comments
 (0)