Reputation: 23
consider this code:
str = "test"
def v():
for i in str:
k = k + i
print(k)
I don't want to assign k anything at all. I used k = None
to define empty variable but that doesn't work.
Upvotes: 1
Views: 11143
Reputation: 10811
Simple as this:
str="test"
def v():
k = ""
for i in str:
k=k+i
print(k)
Another advice, str
is a built-in type in python you maybe would like to change it for:
string="test"
def v():
k = ""
for i in string:
k=k+i
print(k)
Upvotes: 2