mardi 5 mai 2015

What's happens in Ruby and Python? Why the variable wil be nil in if block in ruby ,but undefined in python?

This question already has an answer Confusion with the assignment operation inside a falsy `if` block

  if false
      y = 'hi'
   end

  puts y

In ruby y has been "defined" in the if block,it will be nil(why?). Remove that block and this gives an error.

But, in python

 if False:
   y = 'hi'

 print y

It will gives an error.

What's happens in Ruby and Python?

Aucun commentaire:

Enregistrer un commentaire