
Python
目睹整个事件的易先生
将来的模样,我正在雕刻
展开
-
python中sort的排序reverse
#list(reverse):sort默认升序,reverse为true,则降序,false升序list = [3,5,6,2,21,2,665,7]list.sort(reverse = True)#降序print(list)list1 = [3,46,2,834,1]list1.sort(reverse = False)#升序print(list1)[665, 21, 7, 6, 5, 3, 2, 2][1, 2, 3, 46, 834]...原创 2020-10-17 11:17:07 · 3366 阅读 · 0 评论 -
python中列表删除数据函数del,pop,remove,clear的用法
name_list = ['tom', 'yi']#del list_name :删除列表del name_listprint(name_list)运行结果:Traceback (most recent call last): File "E:/python/Pycharm/code/test/list_delete.py", line 4, in <module> print(name_list)NameError: name 'name_list' is not de原创 2020-10-17 11:03:18 · 1284 阅读 · 0 评论 -
python中添加数据函数append,extend,insert的区别和用法
name_list = ['Tom', 'Bob', 'Yi']#append():列表结尾添加数据,如果添加的是一个整体,则按照一个整体添加进去name_list.append('yiguang')print(name_list)name_list.append(['qi', 'zhu'])print(name_list)name_list1 = ['tom', 'yi']#extend:列表结尾添加数据,如果数据是一个序列,则将序列里面的数据依次添加到列表中name_list1.ext原创 2020-10-17 10:35:56 · 456 阅读 · 0 评论 -
Python中判断字符串中只有字符或者数字isalpha,isdigit,isalnum
在这里插入代码片#isalpha():如果字符串中所有的都是字符,则返回true,否则falsestr1 = 'asdasd'str2 = 'sdfs32'print(str1.isalpha())print(str2.isalpha())#isdigit()如果字符串中全是数字则返回true,否则返回falsestr3 = '12432'print(str3.isdigit())```TrueFalseTrue...原创 2020-10-17 09:42:35 · 686 阅读 · 0 评论 -
Python中判断以某个字符串开头或者结尾startswith,endswith
#startswith():检查字符串是否以某个子串开头,是返回true,不是返回false,如果设定了开始和结束下标,则在指定范围内寻找#startswith(str,starts,ends)str = 'apple is a blue apple'print(str.startswith('apple'))print(str.startswith('is', 2, 10))#endswith()以某个子串结尾print(str.endswith('e'))TrueFalseTrue原创 2020-10-17 09:34:19 · 2052 阅读 · 0 评论 -
Python中字符串的左右对其居中和填充
#ljust(长度,填充字符):左对齐str = 'apple'str1 = str.ljust(10,'.')print(str1)#rjust:右对齐str2 = str.rjust(10,'.')print(str2)#center:居中str3 = str.center(10,'.')print(str3)apple..........apple..apple...原创 2020-10-17 09:08:11 · 1862 阅读 · 0 评论 -
Python中删除字符串左右空格函数,lstrip,rstrip,strip
tr = ' i hava a apple '#lstrip:删除字符串左侧的空白字符str1 = str.lstrip()print(str1)#rstrip:删除字符串右侧的空白字符str2 = str.rstrip()print(str2)#strip:删除字符串两侧的空白字符str3 = str.strip()print(str3)i hava a apple i hava a applei hava a apple...原创 2020-10-17 08:54:39 · 2342 阅读 · 0 评论 -
Python 中字符串大小写转换,lower,upper,title,capitalize得用法
#title():把每个单词的首字符转换为大写str = 'i have a Apple'new_str = str.title()print(new_str)#capitalize():让字符串只有首字符大写str1 = str.capitalize()print(str1)#upper:所有单词转换为大写str2 = str.upper()print(str2)#lower:所有单词转换为小写str3 = str.lower()print(str3)I Have A Appl原创 2020-10-17 08:48:27 · 508 阅读 · 0 评论 -
Python 中字符串连接操作join用法
Python 中字符串连接操作join用法str1 = 'e and wer and asdasd and lk and jad'list1 = str1.split('and')print(list1)print(str1)#切片并不会改变原有字符串new_str = '-111-'.join(list1)#此处‘-111-‘字符串也可以换成其他想要的字符串print(new_str)E:\anaconda\python.exe E:/python/Pycharm/code/test/s原创 2020-10-16 22:22:52 · 504 阅读 · 0 评论 -
Python 字符串的切片split用法
str1 = 'e and wer and asdasd and lk and jad'list1 = str1.split('and')#默认切所有的print(list1)`['e ', ' wer ', ' asdasd ', ' lk ', ' jad']``str1 = 'e and wer and asdasd and lk and jad'list1 = str1.split('and',2)#切前面两个,得到的列表元素个数等于切片次数加1print(list1)['e原创 2020-10-16 22:15:03 · 477 阅读 · 0 评论 -
Python中for else break continue的用法
当for中的循环正常结束的时候,遇到continue算是正常执行,else下面的语句就执行当for中的循环非正常结束,也就是遇到break终止,则else下面的语句不执行正常循环执行:str = 'python'for i in str: print(i)else: print('啦啦啦')python啦啦啦break终止执行:tr = 'python'for i in str: if i == 'o': break prin原创 2020-10-16 20:32:28 · 965 阅读 · 0 评论 -
python中while else continue的使用
在while循环中,continue执行之后,还是算循环正常结束,会执行else后面的语句i = 1while i <= 5: if i == 4: i += 1 continue print(f'{i}') i += 1else: print('啦啦啦')E:\anaconda\python.exe E:/python/Pycharm/code/test/cycle.py1235啦啦啦...原创 2020-10-16 20:21:17 · 587 阅读 · 0 评论 -
python中while else break的使用
当while中的循环正常结束的时候,else下面的语句就执行当while中的循环非正常结束,也就是遇到break终止,则else下面的语句不执行非正常终止:i = 1while i <= 5: if i == 4: break print(f'{i}') i += 1else: print('啦啦啦')E:\anaconda\python.exe E:/python/Pycharm/code/test/cycle.py123Pro原创 2020-10-16 20:16:29 · 1270 阅读 · 0 评论 -
Python写99乘法口诀表
i = 1while i <= 9: j = 1 while j <= i: print(f'{j} * {i} = {i*j}', end = ' ') j += 1 print('\n') i += 1原创 2020-10-16 17:23:06 · 265 阅读 · 0 评论 -
Python中 countinue和break的区别
举个吃苹果的例子:假设吃一个苹果是循环一次,没吃饱就继续吃,一直循环,吃100个break:张三在吃苹果的过程中,吃了20个吃饱了,吃不下了,不能再继续吃下去,即停止吃苹果,去干其他的事,也就是break,终止吃苹果这个过程、continue:张三吃苹果吃到第88个的时候,发现苹果里面有个虫子,他就不想吃这个苹果了,就停止了吃第88个苹果这个过程,开始吃第89个,继续吃,也就是continue。breaki = 1while i <= 100 : if i==20:原创 2020-10-16 17:07:12 · 1156 阅读 · 1 评论 -
Figures now render in the Plots pane by default. To make them also appear inline in the Console, unc
中国大学慕课MOOCPython数据分析与展示使用Anaconda Spider进行数据图形可视化出现的图像不显示问题可以设置:tools-preferences然后设置graphics,选择completion中的Graphical最后重启Spider就可以了原创 2020-09-22 19:22:15 · 3494 阅读 · 3 评论 -
100以内素数之和
100以内素数之和描述求100以内所有素数之和并输出。素数指从大于1,且仅能被1和自己整除的整数。提示:可以逐一判断10原创 2020-07-04 18:35:37 · 2259 阅读 · 1 评论 -
四位玫瑰数
四位玫瑰数描述四位玫瑰数是4位数的自幂数。自幂数是指一个 n 位数,它的每个位上的数字的 n 次幂之和等于它本身。例如:当原创 2020-07-04 18:06:28 · 499 阅读 · 0 评论 -
Python 平方根格式化
平方根格式化描述获得用户输入的一个整数a,计算a的平方根,保留小数点后3位,并打印输出。输出结果采用宽度30个字符、右对齐输出、多余字符采用加号(+)填充。原创 2020-06-26 16:07:40 · 2336 阅读 · 1 评论 -
Python 字符串分段组合
字符串分段组合描述获得输入的一个字符串s,以字符减号(-)分割s,将其中首尾两段用加号(+)组合后输出。原创 2020-06-26 16:05:18 · 6892 阅读 · 1 评论