Suppose i have a list l=[1,2,3]
i want to make this list as [2,3,4] i.e. add 1 to all the values in list l.
I want to do it by the method of for loop.. Can someone help?
utkarshsahu 0 Newbie Poster
Recommended Answers
Jump to PostYou must initialize the newlist out of the loop otherwise you reset before you add next one and you are left with the last value in the list.
Jump to PostThe one without indexes is considered often more 'pythonic', but of course sometimes it more usefull to use indexes. You lost your indention in posting code, put empty line and line with ~~~ before and opposite order after you code, or paint it after pasting and push Tab.
All 6 Replies
JoshuaBurleson 23 Posting Whiz
utkarshsahu 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
utkarshsahu 0 Newbie Poster
utkarshsahu 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.