Skip to main content
Typo.
Source Link
Jens
  • 73.3k
  • 16
  • 134
  • 186

In the first case the global keyword is pointless, so that is not correct. Defining a variable on the module level makes it a global variable, you don't need tothe global keyword.

The second example is correct usage.

However, the most common usage for global variables are without using the global keyword anywhere. The global keyword is needed only if you want to reassign the global variables in the function/method.

In the first case the global keyword is pointless, so that is not correct. Defining a variable on the module level makes it a global variable, you don't need to global keyword.

The second example is correct usage.

However, the most common usage for global variables are without using the global keyword anywhere. The global keyword is needed only if you want to reassign the global variables in the function/method.

In the first case the global keyword is pointless, so that is not correct. Defining a variable on the module level makes it a global variable, you don't need the global keyword.

The second example is correct usage.

However, the most common usage for global variables are without using the global keyword anywhere. The global keyword is needed only if you want to reassign the global variables in the function/method.

Some clarification.
Source Link
Lennart Regebro
  • 173.2k
  • 45
  • 230
  • 254

In the first case the global keyword is pointless, so that is not correct. But dropDefining a variable on the module level makes it a global keywordvariable, and ityou don't need to global keyword.

The second example is a correct usage. So is the second one. 

However, the most common usage for global variables are without using the global keyword anywhere.

  The global keyword is needed only if you want to reassignreassign the global variables in the function/method. Otherwise not.

In the first case the global keyword is pointless, so that is not correct. But drop the global keyword, and it is a correct usage. So is the second one. However, the most common usage for global variables are without using the global keyword anywhere.

  The global keyword is needed if you want to reassign the global variables in the function/method. Otherwise not.

In the first case the global keyword is pointless, so that is not correct. Defining a variable on the module level makes it a global variable, you don't need to global keyword.

The second example is correct usage. 

However, the most common usage for global variables are without using the global keyword anywhere. The global keyword is needed only if you want to reassign the global variables in the function/method.

Source Link
Lennart Regebro
  • 173.2k
  • 45
  • 230
  • 254

In the first case the global keyword is pointless, so that is not correct. But drop the global keyword, and it is a correct usage. So is the second one. However, the most common usage for global variables are without using the global keyword anywhere.

The global keyword is needed if you want to reassign the global variables in the function/method. Otherwise not.