Ask Your Question

damodar's profile - activity

2019-05-28 04:56:14 -0600 received badge  Popular Question (source)
2018-10-16 12:29:57 -0600 answered a question How to implement "positional-only parameter" in a user defined function?

ok i got it . Those are built-in functions (builtin_function_or_method), not user-defined functions (function). They are implemented in C, into python library. These functions are not exposed at the Python level.

2018-10-16 08:54:43 -0600 asked a question Is there any difference between the variables b and *b in these two statements? If so, what is it?
        (a, b, c) = 1, 2, 3
        (a, *b, c) = 1, 2, 3
2018-10-16 06:30:20 -0600 commented answer How to implement "positional-only parameter" in a user defined function?

Examples:

 def fun( a, b): 
        print(a**b)
 fun(a=5, b=2)   # 25
 fun(b=2,a=5)    # 25
 fun(5,2)        # 25




 def fun( a, b, /): 
        print(a**b)
 fun(5,2)        # 25
 fun(a=5, b=2)   # should show error
2018-10-16 06:16:38 -0600 commented answer How to implement "positional-only parameter" in a user defined function?

help(pow)

o/p:
-----
Help on built-in function pow in module builtins:

pow(x, y, z=None, /)
Equivalent to x**y (with two arguments) or x**y % z (with three arguments)

Some types, such as ints, are able to use a more efficient algorithm when
invoked using the three argument form.

I want to know can we write a user defined function like pow (), which has positional only parameter.

2018-10-16 06:10:12 -0600 commented answer How to implement "positional-only parameter" in a user defined function?
2018-10-16 04:23:40 -0600 asked a question How to implement "positional-only parameter" in a user defined function?

def fun( a, b, /): print(a,b)

o/p:

File "<ipython-input-36-1fceb840aeb9>", line 1 def fun( a, b, /): ^ SyntaxError: invalid syntax

2018-10-14 14:35:46 -0600 received badge  Supporter (source)
2018-10-14 14:29:56 -0600 commented question list as a function parameter.

yes i got my solution. thanq

2018-10-14 01:57:04 -0600 commented question list as a function parameter.

I can't able to understand how the outputs work.

2018-10-14 01:53:20 -0600 edited question list as a function parameter.

.

>>> def fun(x, b= []):
...   b.append(x)
...   print(x,'   ',b)
...
>>> fun(7)
7     [7]
>>> fun([9, 7])
[9, 7]     [7, [9, 7]]
>>> fun([9, 8])
[9, 8]     [7, [9, 7], [9, 8]]
>>>