看啥推荐读物
专栏名称: 小白学视觉
本公众号主要介绍机器视觉基础知识和新闻,以及在学习机器视觉时遇到的各种纠结和坑的心路历程。
今天看啥  ›  专栏  ›  小白学视觉

你需要知道的20个常用的Python技巧

小白学视觉  · 公众号  ·  · 2024-05-01 15:15
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达来源: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 ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照