点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达来源:https://medium.com翻译:小马Python的可读性和简单性是其广受欢迎的两大原因,本文介绍20个常用的Python技巧来提高代码的可读性,并能帮助你节省大量时间,下面的技巧将在你的日常编码练习中非常实用。1.字符串反转使用Python切片反转字符串:# Reversing a string using slicingmy_string = "ABCDE"reversed_string = my_string[::-1]print(reversed_string)# Output# EDCBA2.每个单词的第一个字母大写使用title函数方法:my_string = "my name is chaitanya baweja"# using the title() function of string classnew_string = my_string.title()print(new_string)# Output# My Name Is Chaitanya Baweja3. 字符串查找唯一元素使用集合的概念查找字符串的唯一元素:my_string = "aavvccccddddeee"# converting the string to a settemp_set = set(my_string)# stitching set into a string using joinnew_st
………………………………