Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

python - What is the meaning of "spam = spam + 1"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As noted, spam = spam + 1 increases the value of spam by one.

That makes more sense if the program you are looking at is actually this:

spam = 0
while spam < 5:
    print('Hello, world.')
    spam = spam + 1

Now the spam = spam + 1 is part of the loop body ... and whole program is going to print "Hello, world" 5 times.

Indentation is significant to the meaning of a program in Python.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...