0

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..

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by vegaseat
0

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)

Edited by snippsat: n/a

0

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.
;)

0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.