forked from balapriyac/python-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (35 loc) · 1.02 KB
/
main.py
File metadata and controls
47 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Positional Arguments
def meet(name,job_title,city):
return f"Meet {name}, a {job_title} from {city}."
meet1 = meet('James','Writer','Nashville')
print(meet1)
# Keyword Arguments
meet3 = meet(city='Madison',name='Ashley',job_title='Developer')
print(meet3)
# Variable Number of Positional Arguments
def reverse_strings(*strings):
reversed_strs = []
for string in strings:
reversed_strs.append(string[::-1])
return reversed_strs
rev_strs2 = reverse_strings('Coding','Is','Fun')
print(rev_strs2) # ['gnidoC', 'sI', 'nuF']
# Variable Number of Keyword Arguments
def running_sum(**nums):
sum = 0
for key,val in nums.items():
sum+=val
return sum
sum1 = running_sum(a=1,b=5,c=10)
print(sum1)
sum2 = running_sum(num1=7,num2=20)
print(sum2)
# Using Default Values for Arguments
def greet(name='there'):
print(f"Hello {name}!")
# Mutable Default Arguments - The Curious Case
def append_to_list(elt,py_list=[]):
py_list.append(elt)
return py_list
greet('Jane')
greet() # Hello there!