plz see this code
x=raw_input('enter any number :')
def adder(d):
d=d+1
adder(x)
in this function when x is passed to function adder ,,is 'x' and 'd' are copy of each other or d is reference of x..
plz see this code
x=raw_input('enter any number :')
def adder(d):
d=d+1
adder(x)
in this function when x is passed to function adder ,,is 'x' and 'd' are copy of each other or d is reference of x..
A print statement should clear it up.
Here first line get run,where user input return an integer.
Then that integer is passed inn as an agument to function adder.
Then d take that value and put result in a new variable d.
Then we print out result.
Because of bad name to variables,this get more confusing than it should be.
x = int(raw_input('enter any number :'))
def adder(d):
d = d + 1
print d
adder(x)
well said ;)
Also d is just there to show the type of variable the method can use. int,char,float ...etc.
But in python variables types are not much worried about since python takes care of that.
;)
Python does "duck typing", look at this example ...
def adder(d):
d = d + d
print d
x = 1
adder(x) # 2
x = 1.5
adder(x) # 3.0
x = 'bon'
adder(x) # bonbon
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.