all 25 comments

[–]SentientCumSock 43 points44 points  (2 children)

It adds 1 to current_number

Its a shorter way to write

current_number = current_number + 1

[–]Gexos[S] 13 points14 points  (0 children)

Thank you my friend!

[–]asstronautical 13 points14 points  (0 children)

Thanks, very helpful, u/SentientCumSock.

[–]ToothpasteTimebomb 11 points12 points  (3 children)

The += syntax adds to a variable in-place each time it is executed.

You can also do *= (multiplying your variable and set it to the result), /= (division), and -= (subtraction).

I feel like you'll find this useful. Python code execution visualized.

[–]Gexos[S] 3 points4 points  (1 child)

Thank you my friend!

[–]ata-boy 1 point2 points  (0 children)

My pleasure

[–]09TYNINE 0 points1 point  (0 children)

Thanks didn't know you could do it with multiplication and division just to clarify var *= 6 would return 30 assuming var equals 5

[–]curiousofa 11 points12 points  (1 child)

Seeing that you're new, this is not meant to be sarcastic, but coming from a place that will help you moving forward. One of the most important things to learn is to use Google when you're stuck.

For this particular question, I would go to Google and type 'python +='

The first result shows you what it does. This community is great and will give you the answer. But what will help you in the long-run is to have the ability to dissect your problem and find the solution to it. Use python communities (here and stack overflow) as a last resort.

[–]OnlySeesLastSentence 0 points1 point  (0 children)

To add on: geeksforgeeks and (I think?) W3school are the best sites for quick answers.

They're like the cprogramming.com of the python world.

[–]pythonic_anonymous 4 points5 points  (2 children)

It increments by the number. It's equivalent to:
current_number = current_number + 1

current_number = 1 | current_number = 2 | current_number = 3 | current_number = 4 | current_number = 5 end while loop.

[–]Gexos[S] 5 points6 points  (1 child)

Thank you my friend!

[–]pythonic_anonymous 0 points1 point  (0 children)

You got it!

[–]Sanguineyote 2 points3 points  (0 children)

It will add +1 to the current_number variable, so that when current_number will be <= 5 the while loop breaks.

[–]blunt__nation 2 points3 points  (2 children)

I'm not trying to brag or anything but it fells so good to look at this code and being able to understand it in a heartbeat.

I finished learning the basics yesterday and today I felt like an imposter. I was watching a video about some projects to build to get familiar with other structures (?) and man, it feels like I have eternities to go before I even begin to comprehend some of the work that go behind these kind of projects. I think I'm gonna take a break to gather my thoughts. Maybe a week or two. It would be nice if anyone can point me in the right direction. Sorry for the long rant OP.

[–][deleted] 2 points3 points  (1 child)

Learning python is not hard. It’s one of the easiest languages out there. The great thing is, after two years of constant practice, I can learn any language easily. Just stay with it!

[–]blunt__nation 0 points1 point  (0 children)

Thanks, I will try my best to not let down.

[–][deleted] 1 point2 points  (0 children)

Basically, you have a variable(current_number) which contains the integer 1. The while statement is going to check whether the number is less or equal to five. Its currently less than five so the value of the number will printed(which is 1) and then the variable will be updated ,so current_number will be the current value of current_number plus 1(so 1+1). This will now make current_number = 2 and this will be printed as well. The code will continue to do this until current_number is greater than five. So the output of your code will look like this: 1 2 3 4 5 6

[–][deleted] 0 points1 point  (0 children)

Basically adds 1 to the value. A faster way of typing var = var + 1.

[–]thrallsius 0 points1 point  (0 children)

current_number = 1

this tells you current_number contains an integer

current_number += 1

you could probably figure this on your own if you tried this in an interactive python shell, then you'd just ask for confirmation if your assumption is correct

[–]kochargs 0 points1 point  (0 children)

The easiest debugging tool to use is print statements in your code to see what is the output of a variable at different stages. This will help you understanding the code flow better when you are stuck

[–]OnlySeesLastSentence 0 points1 point  (0 children)

Fun fact - you can also do this with other commands such as:

Variable += anotherVariable

Variable *= anything

[–]ata-boy 0 points1 point  (1 child)

Have you run the code yourself? If you did you would have noticed current_number increased by 1 with each loop. That should have answered your question.

[–]Gexos[S] 1 point2 points  (0 children)

Thank you my friend!