Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dcff5d0

Browse files
author
Rai Muhammad Haider
committed
2 parents b98c783 + cdc1e10 commit dcff5d0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎Functions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def default_parameter(city='Lahore'):
55
default_parameter('Okara')
66

77

8-
# Function with unknown number of positional arguments (*args)
8+
# Function with unknown number of positional arguments (*args)
99
def unknown_parameters(*name):
1010
print('The name of the winner is', name[1])
1111

@@ -72,14 +72,16 @@ def default_greeting(greet='Good morning'):
7272
print(cube(2))
7373

7474

75-
# Sum using *args
75+
# Sum using *args , *args allows you to pass any number of values to a function. Inside the function, args is a tuple of all the passed values.
76+
# When you don't know how many arguments will be passed.
7677
def sum_all(*args):
7778
return sum(args)
7879

7980
print(sum_all(2, 4, 5, 2))
8081

8182

82-
# Function with keyword arguments (**kwargs)
83+
# Function with keyword arguments (**kwargs) , **kwargs lets you pass any number of keyword arguments (key-value pairs).
84+
# When you want to accept named arguments without knowing what they are in advance.
8385
def print_kwargs(**kwargs):
8486
for key, value in kwargs.items():
8587
print(f"{key}: {value}")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /