python - Changing parts of a string with '#' -


wanted see if i'm going in right direction. have change last 4 characters of string #. i've got 2 ideas far.

first one:

def maskify(cc):    cc = raw_input("enter passcode: ")    n = len(cc)    cc.replace(cc[0:n-4], #)  # 1 gives me unexpected eof while parsing error 

second 1 (i think one's closer because supposedly needs algorithm):

def maskify(cc):    cc = raw_input("enter passcode: ")      n = len(cc)    in range (0, n-4):  # think loop don't know how i'm going use yet       cc.replace(                  #not entirely sure put here    pass                            

the problem in first example # unquoted. need change '#' otherwise parsed start of comment , enclosing parenthesis part of comment. although, fix parsing error.

the problem strings can't change characters inside of them (they immutable). common way around create array of string, change characters want change , convert array string (often using ''.join(character_array)). try that!


Comments