Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2008, 11:12 AM   #1
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Does python have private variables in classes?

Ive been studying python for 3 days right now and upon finishing the section about classes, Ive noticed that they don't have support for private variables, but they provide support for private methods, why is that? am i right? like this

python Syntax (Toggle Plain Text)
  1. class Rectangle(object):
  2. def __init__(self):
  3. self.width=0
  4. self.height=0
  5. def setSize(self,size):
  6. self.width,self.height=size
  7. def getSize(self):
  8. return self.widht,self.height
  9. size = property(getSize,setSize)

you can access some of the variables like this:

python Syntax (Toggle Plain Text)
  1. f=Rectangle()
  2. f.width=10
  3. f.height=23

Ive programmed in c++, and im not a guru, but im a bit puzzled cause how can python support data hiding? what's the main difference of a c++ class in regards to python class with respect to data hiding? perhaps i haven't read the other part of the book that would clear this up but can you help me please... Thanks a bunch
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Old Jun 22nd, 2008, 8:25 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Does python have private variables in classes?

Python supports pseudo-private variables which are prefixed by two underscores: __width, for example.
titaniumdecoy is offline   Reply With Quote
Old Jun 22nd, 2008, 9:03 PM   #3
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Re: Does python have private variables in classes?

thank you so much.... its clear to me now....
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
more problems with copying from classes cwl157 Java 0 Sep 19th, 2007 5:17 PM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 12:35 PM
Convert Python script to C++ code clanotheduck Python 17 Sep 25th, 2005 9:55 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 8:39 AM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 1:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:28 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC