3 Replies - 1179 Views - Last Post: 08 May 2010 - 12:29 PM Rate Topic: -----

#1 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

A little confusion on variables in python

Posted 05 May 2010 - 12:36 PM

This hasn't been a problem before, but before I continue my programming adventures I need clarification in the differences between Global Variables, Local variables, and constants.
From my understanding Global variables are initialized outside of everything, usually I put mine at the beginning of the code, after the heading. And its correct to put them in all caps right?
like GLOBAL_A for example

Local variables are initialized in functions and only used in those functions, pretty sure thats correct

Constants are what I'm confused with, they seem sort of like a global variable to me. I'm not sure where to initialize them and do I put them in all caps?

Or could it be that constants and global variables are the same thing?
Someone clear this up for me please.

Is This A Good Question/Topic? 0
  • +

Replies To: A little confusion on variables in python

#2 Smurphy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 367
  • Joined: 07-July 08

Re: A little confusion on variables in python

Posted 05 May 2010 - 01:37 PM

You are right globals are outside of everything. Now the thing about constants is that they are constant (they never ever change) That is the difference between globals and constants, globals can change and constants can not. Yes I would say to put constants in all caps and at the top of the code.
Was This Post Helpful? 0
  • +
  • -

#3 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

Re: A little confusion on variables in python

Posted 05 May 2010 - 09:55 PM

awesome thanks for the help!
Was This Post Helpful? 0
  • +
  • -

#4 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: A little confusion on variables in python

Posted 08 May 2010 - 12:29 PM

Python doesn't have real constants, they are the same as global variables.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1