-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions().py
More file actions
147 lines (133 loc) · 3.66 KB
/
Copy pathFunctions().py
File metadata and controls
147 lines (133 loc) · 3.66 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Function()
#User Defined Function #Basics
print('start')
def greet():
print(f"hello, Welcome")
#fn(📞)
greet()
print('end')
#Case 1.0
def mult_two(x):
print(x * 3)
#fn(📞)
mult_two(6)
#UDF #Intermediate
#case 1.1
#buillding up a fn()
name = ' MariA '
print(name.strip().lower())
#hardcoded fn() build_up
def clean_code():
name = ' MariA '
print(name.strip().lower())
#fn(📞)
clean_code()
#Dynamic fn() Build_up
def clean_code(name):
print(name.strip().lower())
#fn(📞)
clean_code(' MariA ')
clean_code('SMITH ')
#Global Variables
f = 4 #Global vrble
def multi_tw(x):
print(x * f)
#fn(📞)
multi_tw(7)
#Local variable
f = 4 #Global vrble #F
def multi_tw(x): #parameter #X
y = x * f #lcal vrble #Y
print(y)
#fn(📞)
multi_tw(10)
#case 1.0.1 #Local variable
def clean_txt(name):
cleaned = name.strip().lower().replace(" ","") #lcl vrbl
print(cleaned)
#fn(📞)
clean_txt(' MaRiA ')
clean_txt(' SMAT HY')
clean_txt(' Fo w A VE s')
#case 1.0.2 #global variable
case_rule = " " #glbl vrble
def clean_txt(name): #parameter
cleaned = name.strip().lower() #lcl vrbl
if case_rule == " ":
cleaned = cleaned.replace(" ","")
print(f'raw: {name}')
print(f'cleaned: {cleaned}\n')
#Fn(📞)
clean_txt(' MaRiA ')
clean_txt(' SMAT HY')
clean_txt(' Fo w A VE s')
#UDF #Advanced
#Building Full Clean Name
#Positional Arguments
def clean_name(nom,prenom,country):
first = nom.strip().lower().replace(" ","")
last = prenom.strip().lower().replace(" ","")
name = first + " " + last
print(f'{name} from {country}')
#Fn(📞)
clean_name(' MaRiA ',' SMAT HY',"DE")
clean_name('EG',' MaRiA ',' Fo w A VE s') #Positional error wont be corrected
clean_name('SMiTHy ',' Fo w A VE s','FR')
#Keyword Arguments
def clean_name(nom,prenom,country):
first = nom.strip().lower().replace(" ","")
last = prenom.strip().lower().replace(" ","")
name = first + " " + last
print(f'{name} from {country}')
#Fn(📞)
clean_name(country = 'DE', nom = ' MaRiA ', prenom = ' SMAT HY')
#keyword Arguments corrects position error
clean_name(prenom =' Fo w A VE s',country = 'FR' ,nom = 'SMiTHy ')
#if arrangementsbgets messed up, it still works correct
#Mixed Arguments #Rule:Always starts with #Pos Args
def clean_name(nom,prenom,country):
first = nom.strip().lower().replace(" ","")
last = prenom.strip().lower().replace(" ","")
name = first + " " + last
print(f'{name} from {country}')
#Fn(📞)
clean_name(' MaRiA ',' SMAT HY',country = 'DE')
clean_name('SMiTHy ',prenom = ' Fo w A VE s',country = 'FR')
#Stick to one of both, forget #Mixed Args
#Default Parameters
#Rules #parameters with a default fllws one without a default
def clean_name(nom,prenom,country = 'unknown'):
first = nom.strip().lower().replace(" ","")
last = prenom.strip().lower().replace(" ","")
name = first + " " + last
print(f'{name} from {country}')
#Fn(📞)
clean_name(' MaRiA ',' SMAT HY') #omitting country argument here
clean_name(' MaRiA ',' Fo w A VE s', 'EG')
# *ARGS and **KWARGS
#task #calculating the total of values
def total (a=0,b=0,c=0,d=0):
print(a+b+c+d) #adding more from three paramtrs
total(2,3,1,4) #totally stressful instead
#*ARGS
def total(*args):
print(sum(args))
#fn(📞)
total(2,3,4,5,6,7,8) #Now adding more arguments without stressing
#Case 2 #**KWARGS
#A mix of different value type
def user_profile(**kwargs):
print(kwargs)
#fn(📞)
user_profile( nom = 'christiano',
prenom ='ronaldo',
age = 40,
height = '185cm',
pays ='portugal')
print(f'\n')
user_profile( nom = 'ademola',
prenom ='lookman',
age = 25,
height = '181cm',
pays ='nigeria',
club = 'Ac Milan')