Ask Your Question

damodar's profile - activity

2022-06-06 14:44:24 +0200 received badge  Popular Question (source)
2019-05-28 11:56:14 +0200 received badge  Popular Question (source)
2018-10-16 19:29:57 +0200 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 15:54:43 +0200 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 13:30:20 +0200 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 13:16:38 +0200 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 13:10:12 +0200 commented answer How to implement "positional-only parameter" in a user defined function?
2018-10-16 11:23:40 +0200 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 21:35:46 +0200 received badge  Supporter (source)
2018-10-14 21:29:56 +0200 commented question list as a function parameter.

yes i got my solution. thanq

2018-10-14 08:57:04 +0200 commented question list as a function parameter.

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

2018-10-14 08:54:54 +0200 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]]
>>>