- 博客(8)
- 收藏
- 关注
转载 python中,list()切片方法
list()切片 python为list提供了功能强大的切片功能。 """ 使用模式: [start:end:step] 其中start表示切片开始的位置,默认是0 end表示切片截止的位置(不包含),默认是列表长度 step表示切片的步长,默认是1 当start是0时,可以省略;当end是列表的长度时,可以省略. 当step是1时,也可以省略,并且省略步长时可以同时省略最后一个冒号. 此外,当step为负数时,表示反向切片,这时start值应该比end值大.
2021-08-17 17:03:29
18698
原创 python字符串,特定字符的删除问题
分析 python中,字符串是不可变的,所以无法直接删除字符串之间的特定字符。 所以如果想要对字符串中的字符进行操作的时候,可以先把字符串转化成列表,再对列表进行相应操作。 1、删除指定位置字符 对列表使用**.pop()**方法 s='abcde' str_list=list(s) str_list.pop(0) s=''.join(str_list) print(s) #输出为:bcde 2、删除指定字符 2.1 列表实现 和删除指定位置方法同理 s='abcde' str_list=list(s
2021-08-17 10:11:53
2388
转载 Python ASCII码与字符相互转换
# Filename : test.py # author by : www.runoob.com # 用户输入字符 c = input("请输入一个字符: ") # 用户输入ASCII码,并将输入的数字转为整型 a = int(input("请输入一个ASCII码: ")) print( c + " 的ASCII 码为", ord(c)) print( a , " 对应的字符为", chr(a)) 执行以上代码输出结果为: ** 请输入一个字符: a 请输入一个ASCII码: 101 a
2021-08-15 14:59:47
1226
原创 python中list()的查找方法
一、list五种查找方式 in,not in,count,index,find前两种方法是保留字,后两种是列表的方法 二、函数EXA #判断值a是否在列表中,并返回True或False 'a' in lst 'a' not in lst #统计指定值在列表中出现的次数,count(value)方法: lst.count('a') #index返回指定值在列表中的位置,不存在返回异常,index(value,,[start,stop]) lst.index('a') #index函数,string类型才能用,
2021-08-15 14:56:20
8163
原创 7.13-20The first week:Learning experience
7.13学习心得 vector vector<Man>men; men[0].push_back(liuBei); //men.pop() //men[0] is different with liuBei,and it is copy of liuBei men[0].getcount(); liuBei.getcount();
2021-07-17 10:31:23
155
原创 Prime Number
Prime Number 埃氏筛法: #include #include #include using namespace std; const int maxn = 10000000; int prime[maxn]; bool IsPrime[maxn] = {0};//0代表都是素数 void Find_Prime(){ IsPrime[1] = 1;//1不是素数 int pNum = 1; for(int i = 2; i <= maxn; i++){ if(!IsPrime[i])
2021-03-19 09:34:05
192
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅
1