class vs function ???
From: Gaurav Veda (gveda_at_iitk.ac.in)
Date: 02/21/04
- Next message: David Opstad: "Linguistically correct Python text rendering"
- Previous message: Robin Bryce: "Re: running fastcgi on windows?"
- Next in thread: Josiah Carlson: "Re: class vs function ???"
- Reply: Josiah Carlson: "Re: class vs function ???"
- Reply: Sean Ross: "Re: class vs function ???"
- Reply: John Roth: "Re: class vs function ???"
- Reply: Rainer Deyke: "Re: class vs function ???"
- Reply: Scott David Daniels: "Re: class vs function ???"
- Reply: Alan Gauld: "Re: class vs function ???"
- Reply: Shalabh Chaturvedi: "Re: class vs function ???"
- Reply: Stephen Horne: "Re: class vs function ???"
- Reply: Stephen Horne: "Re: class vs function ???"
- Reply: Gaurav Veda: "Re: class vs function ???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Feb 2004 08:57:44 -0800
Hi !
I am a poor mortal who has become terrified of Python. It seems to
have thrown all the OO concepts out of the window. Penniless, I ask a
basic question :
What is the difference between a class and a function in Python ???
Consider the following code fragments :
# Fragment 1 begins
a = 1
print a
def fun1():
global b
b = "inside fun1"
print b
fun1()
def c1():
print a
print b
c = 12
def fun2():
global d
d = "We are dead !!!"
print d
fun2()
c1()
class c2:
pass
print d
print c
# Fragment 1 ends
# Fragment 2 begins
a = 1
print a
def fun1():
global b
b = "inside fun1"
print b
fun1()
class c1:
print a
print b
c = 12
def fun2():
global d
d = "We are dead !!!"
print d
fun2()
class c2:
pass
print d
print c
# Fragment 2 ends
The output of both these codes are precisely the same ! (including the
error because of 'print c')
The sample output is :
1
inside fun1
1
inside fun1
We are dead !!!
We are dead !!!
Traceback (most recent call last):
File "XYZ.py", line 21, in ?
print c
NameError: name 'c' is not defined
Waiting for some 'logical' explanation !!!
Gaurav
- Next message: David Opstad: "Linguistically correct Python text rendering"
- Previous message: Robin Bryce: "Re: running fastcgi on windows?"
- Next in thread: Josiah Carlson: "Re: class vs function ???"
- Reply: Josiah Carlson: "Re: class vs function ???"
- Reply: Sean Ross: "Re: class vs function ???"
- Reply: John Roth: "Re: class vs function ???"
- Reply: Rainer Deyke: "Re: class vs function ???"
- Reply: Scott David Daniels: "Re: class vs function ???"
- Reply: Alan Gauld: "Re: class vs function ???"
- Reply: Shalabh Chaturvedi: "Re: class vs function ???"
- Reply: Stephen Horne: "Re: class vs function ???"
- Reply: Stephen Horne: "Re: class vs function ???"
- Reply: Gaurav Veda: "Re: class vs function ???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|