Mind
Mind

Reputation: 23

how to define empty variable in python

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

Answers (1)

Victor Castillo Torres
Victor Castillo Torres

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

Related Questions