Home > other >  Small white help why not replace string
Small white help why not replace string

Time:10-09

W=input (' 93 python22)
For x in w: if '0' & lt;=x & lt;='9' : continue the else, w.r eplace (x, ' ')
Print (w)

CodePudding user response:

The replace () method returns a new string object, does not modify the original string,
 
In [7] : w='93 python22'

In [8], w.r eplace (' p ', ')
The Out [8] : '93 ython22'

In [9] : w
The Out [9] : '93 python22'


CodePudding user response:

 
W='93 python22'
For x in w:
If '0' & lt;=x & lt; :='9'
The continue
The else:
W=w.r eplace (x, ' ')

Print (w)

CodePudding user response:

String is a constant cannot be modified

CodePudding user response:

The
reference 2 floor Vv. Stone3 response:
 
W='93 python22'
For x in w:
If '0' & lt;=x & lt; :='9'
The continue
The else:
W=w.r eplace (x, ' ')

Print (w)
or not

CodePudding user response:

reference 1/f, brother huang Python training response:
the replace () method returns a new string object, does not modify the original string,
 
In [7] : w='93 python22'

In [8], w.r eplace (' p ', ')
The Out [8] : '93 ython22'

In [9] : w
The Out [9] : '93 python22'
that I reset a variable or not

CodePudding user response:

The
reference 2 floor Vv. Stone3 response:
 
W='93 python22'
For x in w:
If '0' & lt;=x & lt; :='9'
The continue
The else:
W=w.r eplace (x, ' ')

Print (w)
oh oh oh ok sorry

CodePudding user response:

The original string is an immutable object
It can be
 


In [17] : w='93 python22'

In [18] : s=""

In [19] : for char In w:
. : if char. Isdigit () :
. : s +=char
. :

In [20] : s
The Out [20] : '9322'

In [21] :

  • Related