
Python基础
yuhui_2000
这个作者很懒,什么都没留下…
展开
-
sort()与sorted()的用法
导入sort()与sorted()这两个函数都是用于列表的排序sort()用法: 待排序的列表.sort()没有返回值,直接在原有列表的基础之上进行修改,待排序的列表被修改为已经排好序的列表a=[32, 105, 16, 149, 20, 15, 149]a.sort()asorted()用法:列表名=sorted(待排序的列表)不在原有列表的基础上修改,而是返回一个排好序的列表b=[15, 16, 20, 32, 105, 149, 149]c=sorted(b)c总原创 2020-11-10 21:22:39 · 821 阅读 · 0 评论 -
python学习网站
1.力扣https://leetcode-cn.com/2.领扣https://www.lintcode.com/3.赛码https://www.acmcoder.com/index4.牛客网https://www.nowcoder.com/5.codewarshttps://www.codewars.com/about/terms-of-service6.Virtual Judgehttps://vjudge.net/原创 2020-11-02 12:38:40 · 103 阅读 · 0 评论 -
Python骚操作3
2.链式函数调用可以在一行代码内调用多个函数def add(a,b): return a+bdef subtract(a,b): return a-ba,b=4,5print((subtract if a>b else add)(a,b))3.检查重复项检查两个列表是否有重复项def has_duplicate(list1): if len(list1)==len(set(list1)): print("没有") els原创 2020-11-02 12:24:51 · 891 阅读 · 1 评论 -
Python骚操作2
1.冒泡排序list1=[1,22,5,6,45,33,25]def bubble_sort(list1): for i in range(len(list1)-1): for j in range(len(list1)-1-i): if list1[j]>list1[j+1]: list1[j],list1[j+1]=list1[j+1],list1[j] return list12.计算x的n次方的原创 2020-11-01 23:41:47 · 284 阅读 · 0 评论 -
python骚操作
1.字符串的翻转使用切片的操作(简单)使用reduce函数# 方法一str1="nihao,shijie"print(str1[::-1])# 方法二from functools import reduceprint(reduce(lambda x,y:y+x,str1))2.判断字符串是否是回文先将字符串进行翻转操作,然后判断翻转之后的字符串与翻转之前的字符串是否一样def judge_plalindrome(input_str): if input_str原创 2020-10-29 19:35:33 · 791 阅读 · 0 评论 -
属性
来源BV1ty4y1r78Vhttps://www.bilibili.com/video/BV1ty4y1r78V?from=search&seid=10498277808429526200目录原创 2020-10-27 22:48:18 · 98 阅读 · 0 评论 -
extend 与 append 的使用方法
相同点不同点原创 2020-10-26 11:23:21 · 529 阅读 · 0 评论