-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
80 lines (62 loc) · 1.36 KB
/
functions.py
File metadata and controls
80 lines (62 loc) · 1.36 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''def greet():
print("hello world")
# call the function
greet()
print("outside the function")
'''
'''def greet(name):
print("hello", name)
#pass argument
greet("john")
'''
'''
# function call with two values
def add_number(num1, num2):
sum = num1 + num2
print("sum:", sum)
# function call with two values
add_number(5, 4)
'''
#the return statement
# it return a value from the function using the return statement
#function defination
'''
def find_square(num):
result = num*num
return result
#function call
square = find_square(9)
print("square:",square)
'''
'''
#the pass statement
def future_function():
pass
# this will execute without any action or error
future_function()
'''
#built-in functions
#print()
#sqrt() returns square root of a number
#pow() retuens power of a number
import math
'''
# sqrt computes the square root
square_root = math.sqrt(4)
print("square root of 4 is", square_root)
#poe() computes the power
power = pow(2, 3)
print("2 to the power 3 is",power)
'''
'''
# function to sum any number of argument
def add_all(*numbers):
returnsum(numbers)
# pass any number of arguments
print(add_all(1,2,3,4))'''
# function to printkeyword argument
def greet(**words):
for key, value in words.items():
print(f"{key}: {value}")
# pass any number of keyword arguments
greet(name="john", greeting="hello")