Skip to content

Commit da4cc8c

Browse files
committed
Class method
1 parent f06f3b2 commit da4cc8c

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

Employee Class & Static Method.ipynb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 13,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"1.04\n",
13+
"1.04\n",
14+
"1.04\n",
15+
"1.04\n",
16+
"1.04\n",
17+
"1.0\n"
18+
]
19+
}
20+
],
21+
"source": [
22+
"class Employee:\n",
23+
" \n",
24+
" no_empl=0;\n",
25+
" raise_amount=1.04\n",
26+
" \n",
27+
" def __init__(self,f ,l ,p ):\n",
28+
" self.first=f\n",
29+
" self.last=l\n",
30+
" self.email=f+\".\"+l+\"@python.com\"\n",
31+
" self.pay=p\n",
32+
" Employee.no_empl=Employee.no_empl+1\n",
33+
" \n",
34+
" \n",
35+
" def print(self):\n",
36+
" return \"{} {} {} {}\".format(self.first,self.last,self.email,self.pay)\n",
37+
" \n",
38+
" def apply_raise(self):\n",
39+
" self.pay=int(self.pay* self.raise_amount)\n",
40+
" ## Can print using class,self and obj name \n",
41+
" \n",
42+
" @classmethod\n",
43+
" def set_raise_amt(cls,amount):\n",
44+
" cls.raise_amount=amount\n",
45+
" \n",
46+
"emp_1=Employee(\"Soumyadip\",\"Chowdhury\",900000)\n",
47+
"emp_2=Employee(\"Soumyadip\",\"Chowdhury\",100000)\n",
48+
"\n",
49+
"print(Employee.raise_amount)\n",
50+
"print(emp_1.raise_amount)\n",
51+
"print(emp_2.raise_amount)\n",
52+
"\n",
53+
"Employee.set_raise_amt(1.10)\n",
54+
"emp_2.set_raise_amt(1.0)\n",
55+
"\n",
56+
"print(Employee.raise_amount)\n",
57+
"print(emp_1.raise_amount)\n",
58+
"print(emp_2.raise_amount)"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": []
67+
}
68+
],
69+
"metadata": {
70+
"kernelspec": {
71+
"display_name": "Python 3",
72+
"language": "python",
73+
"name": "python3"
74+
},
75+
"language_info": {
76+
"codemirror_mode": {
77+
"name": "ipython",
78+
"version": 3
79+
},
80+
"file_extension": ".py",
81+
"mimetype": "text/x-python",
82+
"name": "python",
83+
"nbconvert_exporter": "python",
84+
"pygments_lexer": "ipython3",
85+
"version": "3.7.4"
86+
}
87+
},
88+
"nbformat": 4,
89+
"nbformat_minor": 4
90+
}

0 commit comments

Comments
 (0)