2013-03-03 2 views
-1

과제를 진행 중이고 앨리스를 내 이름으로 바꿔야합니다. 여기에 프로그램입니다, 파이썬에서 문자열로 이름 바꾸기

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

그래서 난 그냥 프로그램이 대신 앨리스의 내 이름으로 범위 부분에 i을 읽을 수 있도록 도움이 필요합니다.

감사합니다. 당신은 아무것도에 대해 의문이있는 경우

+1

을 작업중인 ?? –

+1

'split_alice' 배열과'replace_alice()'함수를 게시 할 필요가 있습니다. 우리는 당신의 과제를 완전히 완료 할 수 있기 때문에 당신을 위해 그것을 쓸 수는 없습니다. 탄탄한 노력을 기울이면 게시 중단 된 과제를 도와 드리겠습니다. 우리는 완전한 대답을 thoguh 줄 가능성은 희박합니다. –

답변

0

그냥, 또한이

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

처럼 문자열에 replace() 방법 ..
를 사용하여, 당신은 help()를 사용해야합니다. 귀하의 경우처럼
: 당신이 어떤 프로그래밍 언어를

>>> 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 
+0

@divoom을 대신하여 이것을 확인하실 수 있습니다 [파이썬에서, 목록이있는 목록의 색인을 찾으려면 어떻게합니까?] (http://stackoverflow.com/q/176918/1931274) – pradyunsg

관련 문제