У меня стояла задача удалить все пробелы из строки и сделать первую букву каждого слова в строке заглавной, в общем должен был получиться "camel style". В этой статье я хочу поделиться, как это можно сделать легко с помощью Python.
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
string_name = "hi Vlad, welcome to the California" | |
def mv_uppercase_rm_whitespaces(string_name): | |
a = string_name.title() # capitalize the first letter | |
b = a.replace(',', '') # remove comma | |
c = b.replace(' ', '') # remove whitespace | |
print c | |
mv_uppercase_rm_whitespaces(string_name) | |
# result | |
# HiVladWelcomeToTheCalifornia |
Метод title() работает как со строками так и с ASCII, Unicode
Комментариев нет :
Отправить комментарий
Оставить отзыв