-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20 - User Define Functions.py
More file actions
50 lines (39 loc) · 1.46 KB
/
20 - User Define Functions.py
File metadata and controls
50 lines (39 loc) · 1.46 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
#User Defined Funtions in Python Programming Language
""" Why needed:-
1) Code Reuse
2) Modularity
"""
s = "pyhton"
print(s[ : :-1])#nothyp
""" Same concept by using function definition and function call"""
def value_reverse(value): #Value_reverse is name of function we have to use.after def write name of the function and in paranthesis write result which is to be find
reverse = value[ : :-1]
print(reverse)
# This was about function defination(def)
s = "python"
result = value_reverse(s) #nothyp
#And ths was about function calling
#Python can't execute the function without calling it,so if we remove function calling then it will not executed
def value_reverse(value): #Value_reverse is name of function we have to use
reverse = value[ : :-1]
return reverse
s = "python"
result = value_reverse(s)
print(result) #nothyp
l = [100,200,300,400]
result = value_reverse(l)
print(result)#[400, 300, 200, 100]
"""num = 100
result = value_reverse(num) # our striding operation is not work for integer
print(result) #TypeError: 'int' object is not subscriptable """
# So for these there is some modifications in pythoncalling:-
def value_reverse(value):
if type(value)==list or type(value)==str:
reverse = value[ : :-1]
else:
temp = str(value)
reverse = temp[ : :-1]
return reverse
num = 100
result = value_reverse(num)
print(result) #001