0

I have the following function:

def myfunc(str):
    x = str # i need to copy str into x , not but ref

I tesed copy Module but it didn't work.

My question is, How i copy instead of by ref str into x?

4
  • When you say that copy "didn't work" what do you mean? Commented Sep 10, 2013 at 4:28
  • x = str[:] x = copy.copy(str); but i get the TypeError: 'str' object does not support item assignment Commented Sep 10, 2013 at 4:28
  • Don't name your variables str, that might be part of your problem. Commented Sep 10, 2013 at 4:44
  • i renamed, but i goot same error. Commented Sep 10, 2013 at 4:48

1 Answer 1

4

Since strings are immutable, there's no real difference between "by value" and "by reference" in your specific case.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.