0

How do I change the current line? For example, if after assign a value to a variable I want to go back and assign a new value?

myList = [1, 8, 9, 5, 2]

a = 3

for item in myList:
    print(item * a)

On this snippet for example, if after multiply the first element of my list I decide change the value of a = 3 to a = 8, how do I go back and do it?

I am trying to drag the cursor but it is not working. I do it when debugging VBA on Excel so I would like to do the same in Visual Studio Code when debugging Python.

Change the <code>a</code> value

Many thanks!

1 Answer 1

3

Do you mean like this?

myList = [1, 8, 9, 5, 2]

a = 3

for index, item, in enumerate (myList):
    if index == 0: 
        a = 8
    else: 
        a = 3
    print(item * a)

I have casted it as an enumerate, and then i have used an if else to check the value of a.

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

4 Comments

No man... I want to change my code while debugging. Without the needing of stop debugging, change the variable value and then start debugging again.
Hmmm, Not sure what you mean but, because it doesnt sound possible. But anyways, remember to set your breakpoints right while debugging. One thing you can do for testing is to print statements of what you want to "test". codeburst.io/how-i-use-python-debugger-to-fix-code-279f11f75866 Try reading this article.
Sorry, I posted it too quick Furthermore, you can try reading this answer stackoverflow.com/questions/4832478/…
tks for your helping now. Maybe I can do it using PyCharm or other IDE or edtitor like Atom?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.