0

I'm working on a assignment and I need to replace Alice with my name. Here is the program,

for i in range(10):
    print(i)
    print(split_alice[i]).replace_alice("Alice","Alex")

So I just need help to make the program read the i in range part with my name instead of Alice.

Thanks.

2
  • 1
    what programming language are you working on??
    – Greg Oks
    Mar 3, 2013 at 15:21
  • 1
    You are going to need to post the split_alice array and the replace_alice() function. We cannot write that for you, as it would complete your assignment entirely. We are happy to help with an assignment where you are stuck, if you post a solid effort. We're unlikely to give full answers thoguh. Mar 3, 2013 at 15:21

1 Answer 1

0

Just use replace() method on strings..
Like this

>>> mystr = 'My name is Alice'
>>> mystr.replace('Alice','Alex')
'My name is Alex'

Also, if you have any doubts about anything, you should use help().
Like in your case:

>>> help(type(mystr))
Help on class str in module __builtin__:

class str(basestring)
 |  str(object) -> string
...
...
 |  replace(...)
 |      S.replace(old, new[, count]) -> string
 |      
 |      Return a copy of string S with all occurrences of substring
 |      old replaced by new.  If the optional argument count is
 |      given, only the first count occurrences are replaced.
 |  
...
...
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __new__ = <built-in method __new__ of type object>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.