DAY4(python)打印字符串以及增删改查

用while循环打印字符串

#if i in s:

#  print ( i )

s='nanfjkhndaol'

index = 0

while 1 :

  print (s[index])

  index+=1

  if index == len(s) : break

统计输入字符串中的数字

 s = input ('请输入:’)

 count = 0

 for i in s:

  if i . isdigit():

    count + = 1

  print(count)

 增删改查命令

1.增

  append( )  增加一个元素

  extend( )  增加多个元素

  insert( 1 , 'happy' ) 插入具体位置具体元素

2.删

  del(0:2) 删除前两个元素

  remove('happy') 删除具体'happy'元素

  clear() 清空元素

  pop ( )  默认删除最后一个元素

3.改

切片:

    li [ 0 : 2 ]='asdcgsa'

    最后会输出[ a,s,d,c,g,s,a]

  sort ( )  正向排序

  sort ( reverse =  True) 

猜你喜欢

转载自www.cnblogs.com/qq946487854/p/9782851.html