1.交换两个数字x,y=10,20print(x,y)x,y=y,xprint(x,y)输出102020102.反转字符串a="GeeksForGeeks"print("Reverseis",a[::-1])输出反向是skeeGroFskeeG3。连接列表中的元素a=["Geeks","For","Geeks"]print("".join(a))OutputGeeksForGeeks4.多个比较器n=10result=1n<=9print(result)outputTrueFalse5.输出模块位置importos;进口插座;print(os)print(socket)output6。使用枚举类MyName:Geeks,For,Geeks=range(3)print(MyName.Geeks)print(MyName.For)print(MyName.Geeks)输出2127.函数返回多个值defx():return1,2,3,4a,b,c,d=x()print(a,b,c,d)输出12348.在数组test=[1,2,3,4,2,2,3,1,4,4,4]print(max(set(test),key=test.count))输出49.查看对象占用内存大小importsysx=1print(sys.getsizeof(x))output2810.检查两个字符串是否是anagram(字母和出现次数相同)fromcollectionsimportCounterdefis_anagram(str1,str2):returnCounter(str1)==Counter(str2)print(is_anagram('geek','eegk'))print(is_anagram('geek','peek'))输出TrueFalse文章到此结束,如果你喜欢今天的Python实践教程,请继续关注Python实战宝典。如果对您有帮助,请点击下方的赞/观看。有什么问题可以在下方留言区留言,我们会耐心解答!Python实战书(pythondict.com)不只是一本书欢迎关注公众号:Python实战书原文来自Python实战书:Python加速编程效率十大技巧