VPython for Beginners 18 - Global Variables in Python

preview_player
Показать описание
New to VPython? This video series will guide you through!

Global Select by Deepz from the Noun Project
Рекомендации по теме
Комментарии
Автор

as magneat says, a simple variable such as speed_of_light needs to be declared as global in the function but not in the main program. Objects, however, do not seem to need declaration as global in either place.

michaelburns-kaurin
Автор

the advice here is incorrect: you don't have to make variable global when you write it outside of the class. it is already global that way. the word "global" is used only inside the class or function to make variable global from local scope. in general, you should try to avoid using "global" as a parameter inside of some scope. just define speed_of_light at the upper(global) level as you normally would define any variable.

magneat