-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7b092a
commit 58f3f67
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Special cases aren't special enough to break the rules. | ||
|
||
Consider the `capitalize_words()` function below. It uniformly uses the `.capitalize()` method for all words in a string, regardless of their original case. | ||
|
||
This approach exemplifies the principle by avoiding special handling for cases like acronyms or words that are already capitalized. | ||
|
||
This uniform treatment keeps the code simple and consistent, highlighting the elegance of Python's design philosophy. 🐍 😁 | ||
|
||
``` | ||
def capitalize_words(s): | ||
# no extra ifs, one consistent interface | ||
return ' '.join(word.capitalize() for word in s.split()) | ||
print(capitalize_words("hello world")) # Outputs "Hello World" | ||
print(capitalize_words("python is FUN")) # Outputs "Python Is Fun" | ||
``` | ||
|
||
#zen |