==2020年6月15日开始==方法str.title()显示每个首字母大写的单词name="adalovelace"print(name.title())#AdaLovelace方法str.upper()和str.lower()name="AdaLovelace"print(name.upper())#ADALOVELACEprint(name.lower())#adalovelaceprint(name)#AdaLovelace删除空白str.strip()和str.rstrip()前后str.lstrip()str='python'print(str.strip())#'python'print(str.lstrip())#'python'print(str.rstrip())#'python'importthisTheZenofPython,作者TimPeters-美丽胜于丑陋。-明确胜于隐含。-简单胜于复杂。-复杂胜于复杂.-扁平比嵌套好。-稀疏比密集好。-可读性很重要。-特殊情况不足以打破规则。-尽管实用性胜过纯度。-错误永远不应该默默地过去。-除非明确沉默。-在里面面对歧义,拒绝猜测的诱惑。-应该有一个——最好只有一个ne--obviouswaytodoit.-尽管除非你是荷兰人,否则这种方式一开始可能并不明显。-现在总比没有好。-虽然从来没有比现在*正确*更好。-如果实施困难解释一下,这是个坏主意。-如果实现很容易解释,那可能是个好主意。-命名空间是一个很棒的主意——让我们做更多!删除列表中元素的方法-.del()根据索引删除元素,无返回值-.pop()可以添加索引,没有索引时默认删除最后一个元素,并返回该元素。-.remove()根据值删除第一次出现的元素,无索引,有返回值。列表排序-.sort()永久正向排序,不返回-.sort(reverse=Ture)永久反向排序,不返回-sorted(list)临时正向排序,不改变原列表排序,返回。-sorted(list,reverse=Ture)暂时反转排序,不改变原来的列表排序,返回。-.reverse()永久反转列表元素的顺序,并再次反转以恢复原始顺序而不返回。对数字列表执行简单的统计计算>>>digits=[1,2,3,4,5,6,7,8,9,0]>>>min(digits)0>>>max(digits)9>>>sum(digits)45与任意数量的关键字参数(createtuple,*createdictionary)defbuild_profile(first,last,**user_info):"""CreateadictionarycontainingwhatweknowabouttheEverythingabouttheuser"""profile={}profile['first_name']=firstprofile['last_name']=lastforkey,valueinuser_info.items():profile[key]=valuereturnprofileuser_profile=build_profile('albert','einstein',location='princeton',field='physics')print(user_profile)
