11.7 Python练习题

题目地址::https://blog.csdn.net/weixin_43865008/article/details/116997922?utm_source=app&app_version=4.17.2&code=app_1562916241&uLinkId=usr1mkqgl919blen

 

 

#2.列表转化成字符串

s = ['helle','world','yoyo']

print('_'.join(s))

# :分割形成列表,jion合并形成字符串,若是用 .patition()形成三元组

 

#4.打印九九乘法表

for i in range(1,10):

  for j in range(1,i+1):

    print('{}*{}={}\t'.format(j,i,i*j),end='')

  print()

 

#5.字符串查找,返回值为-1
s = 'hello,welcome to my world'
print(s.find('welcome'))

注:find返回-1, index抛出异常

 

 

注:刚开始没有想到用列表的方式计数,注意输出可以通过序列下标索引的方式计数

       count(step,star,end),注意return返回值,才可以输出出数据,否则会none

 

#将字符串去重复并以编码进行排序
s = 'ajldjlajfdljfddd'
a = set(s)
print(a)
b = sorted(a,key=ord)
print(''.join(b))

 

注:一定是集合无序可以去重复!刚开始记错了记成元组了还研究了一会

        ‘ ’.join(a)可以将序列a中的元素用制定方式 ‘  ’ 连接成字符串

 

posted @ 2021-11-07 21:10  阿萍萍萍  阅读(66)  评论(0)    收藏  举报