1/ 局部变量的定义
在所有函数内定义的变量叫局部变量,在函数外的都是全局变量.
for guessTaken in range(1,2): print('Take a guess') guess = int(input()) if(guess < secretNumber): print('your guess too low') elif(guess > secretNumber): print('your guess too high') else: break if(guess == secretNumber): print('oK') else: print('fail')
一定注意,上面描述的guess 是全部变量,因为它没有在函数中定义,故不能算局部变量.