apa itu duck typing python 1

apa itu duck typing python

function calculate(a, b, c) => return (a+b)*c
 
example1 = calculate (1, 2, 3)
example2 = calculate ([1, 2, 3], [4, 5, 6], 2)
example3 = calculate ('apples ', 'and oranges, ', 3)
 
print to_string example1
print to_string example2
print to_string example3

Here is what the above code is Doing:
1. It defines a function called calculate that takes three arguments.
2. It defines three variables, example1, example2, and example3.
3. It assigns the result of calling calculate with the arguments 1, 2, and 3 to example1.
4. It assigns the result of calling calculate with the arguments [1, 2, 3], [4, 5, 6], and 2 to example2.
5. It assigns the result of calling calculate with the arguments ‘apples ‘, ‘and oranges, ‘, and 3 to example3.
6. It prints the value of example1.
7. It prints the value of example2.
8. It prints the value of example3.

Similar Posts