-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_format.py
167 lines (87 loc) · 2.47 KB
/
func_format.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
# coding: utf-8
# * def
# * function name
# * parenthesis , followed by colon
# In[ ]:
def some_function_name():
# code here after indentation
print("Hello function!!")# at this stage by run the code we will get none.
# after a calling a function
some_function_name()
# In[ ]:
# another example of func
def yell_it():
phrase = "Go corona GO!!".upper()
print(phrase)
# calling a func
yell_it()
# # Function parameters
# In[ ]:
def some_func_name(code):
# code here to execute
print(code)
some_func_name(123)
some_func_name("Programming")
some_func_name("Structure")
some_func_name("Algorithm")
type(some_func_name)
# In[ ]:
def _name(code): # inside () defining a parameter variable
# that will be used in function code
print(code.upper() + "!!") # str method
_name("Good Morning") # that parameter variable got a value object
# # Default Argument
# In[ ]:
def _name(code = "Python"): # default paramter value passed
# function code here
print(code.lower() + " ...")
_name("JAVA") # passing a parameter value
_name() # passing no value, it uses default value
# # Creating a function with a return value
# In[ ]:
# assign parameter
def my_msg(phrase):
double = phrase + " & " + phrase
return double # assign return to a value
# function call is replaced by the return value
my_req = my_msg("Calling a return value")
my_se = my_msg("Go Goa Gone!!")
print(my_se)
print(my_req)
# In[ ]:
def my_range(phrase):
phrase = "value added"
# print(phrase)
return phrase
z = my_range("@@@")
print(z)
x = my_range("???")
# my_range("Hello")
print(x)
v = my_range(1)
print(v)
# In[2]:
# example
def make_schedule(period1, period2):
schedule = ("[1st] is "+ period1.title() + ", [2nd] is "+ period2.title())
return schedule
student_schedule = make_schedule("mathematics", "physics")
print("schedule".upper(),student_schedule)
# In[15]:
# another example
def make_schedule(period1, period2, period3):
schedule = print("[1st] is "+ period1.title()+ ", [2nd] is "+ period2.title()+ " , [3rd] is "+ period3.title())
return schedule
make_schedule("chemistry", "computer", "biology")
make_schedule("a1", "a2", "a3")
make_schedule("c1", "c2", "c3")
# In[23]:
def state_one(para1, para2):
return "state_name "+ para1 + " country_name "+ para2
print(state_one("Rajasthan", "India"))
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]: