Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99e95ac

Browse files
committed
2024/03/19 - Adding Demo python files
1 parentdfcb932 commit99e95ac

9 files changed

+351
-3
lines changed

‎concepts/PythonDemo01_Variables.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def _inside_func() -> None:
5151
b=a
5252
print("ID of a ",id(a))
5353
print("ID of b ",id(b))
54-
a=100
55-
print("ID of a after assigning new value ",id(a))
56-
54+
b=100
55+
print("after assigning new value ")
56+
print("ID of a ",id(a))
57+
print("ID of b ",id(b))

‎concepts/PythonDemo04_Functions.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This file gives demo about functions
2+
3+
deffunction_with_arg(arg1,arg2="Pooja"):
4+
print("Value of arg1 ",arg1)
5+
print("Value of arg2 ",arg2)
6+
print("*"*25)
7+
8+
9+
print("Calling function_with_arg with one parameter")
10+
function_with_arg("Rohit")
11+
12+
print("Calling function_with_arg with two parameter values")
13+
function_with_arg("Rohit","Phadtare")
14+
15+
# calling function with arguments name
16+
print("Calling function_with_arg with argument name")
17+
function_with_arg(arg2="Rohit",arg1="Phadtare")
18+
19+
20+
deffunction_var_arg_demo(*args):
21+
print("Inside function_var_arg_demo...")
22+
cnt=1
23+
foriinargs:
24+
print("param{} value is {} ".format(cnt,i))
25+
cnt+=1
26+
27+
print("*"*25)
28+
29+
30+
function_var_arg_demo("Rohit","Prakash","Phadtare")
31+
32+
33+
deffunction_var_karg_demo(**kargs_list):
34+
print("Inside function_var_karg_demo...")
35+
cnt=1
36+
forparam_name,param_valueinkargs_list.items():
37+
print("{} value is {} ".format(param_name,param_value))
38+
cnt+=1
39+
40+
print("*"*25)
41+
42+
43+
function_var_karg_demo(first_name="Rohit",middle_name="Prakash",last_name="Phadtare")
44+
45+
46+
deflambda_func_demo(input_list):
47+
print("Inside lambda_func_demo .. ")
48+
print("Given list : ",input_list)
49+
50+
list_even_num=list(filter(lambdan: (n%2==0),input_list))
51+
52+
print("Filtered list with even values : ",list_even_num)
53+
print("*"*25)
54+
55+
56+
lambda_func_demo(range(10,21))

‎concepts/PythonDemo05_Arrays.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file gives demo about array
2+
fromarrayimport*
3+
4+
# creating array of integers and empty array of float
5+
i_arr=array('i', [10,20,30])
6+
f_arr=array('f')
7+
8+
# Traverse array
9+
foriinrange(len(i_arr)):
10+
print("arr[",i,"]"," - ",i_arr[i])
11+
12+
# insert elements using append and insert method
13+
f_arr.append(11)# no need of index in append method as it will append at end position
14+
print("11 is appeneded in f_arr")
15+
f_arr.insert(0,22)# insert will need index to insert value at that position and adjust old values post insertion
16+
print("22 is inserted in f_arr at 0 index")
17+
f_arr.insert(5,33)# if index is not present then it will add at current last_index + 1 position
18+
print("33 is inserted in f_arr at 5 index")
19+
20+
# update element at last position in arr1
21+
print("f_arr - ",f_arr)
22+
f_arr[-1]=55
23+
print("Post update of element at last position f_arr is - ",f_arr)
24+
25+
# delete element from array
26+
print("Deleting element from i_arr - ",i_arr[0])
27+
deli_arr[0]
28+
print("i_arr post deletion - ",i_arr)
29+
30+
# search element in array
31+
ele=input("enter number to search")
32+
cnt=0
33+
34+
foriinrange(len(i_arr)):
35+
ifi_arr[i]==int(ele):
36+
print("Number {} found at {} position in i_arr".format(ele,i))
37+
cnt+=1
38+
39+
ifcnt==0:
40+
print("number {} is not present in i_arr ".format(ele))
41+
42+
# using in operator
43+
print("Number {} is present in i_arr : ".format(ele),int(ele)ini_arr)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This file gives demo about class and object
2+
3+
# Class Person
4+
classPerson:
5+
def__init__(self,pid,name=None,age=None,gender=None):
6+
"""constructor for person class"""
7+
self.pid=pid
8+
self.name=name
9+
self.age=age
10+
self._gender=gender
11+
12+
defdisplay_person_details(self):
13+
print("Person details are -")
14+
print("ID: ",self.pid," Name: ",self.name," Age : ",
15+
self.age," Gender : ",self._gender)
16+
print("*"*100)
17+
18+
19+
# Creating Object
20+
p1=Person(1,"Rohit Phadtare",31,'M')
21+
p2=Person(2)
22+
23+
p1.display_person_details()
24+
p2.display_person_details()
25+
26+
27+
classShape:
28+
29+
def__init__(self,name_of_shape):
30+
self._name=name_of_shape
31+
32+
def__str__(self):
33+
return"Shape is "+self._name
34+
35+
36+
my_shape=Shape("Circle")
37+
print(my_shape)
38+
39+
for_inrange(100):
40+
print(_)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file gives demo about multilevel inheritance
2+
3+
classAnimal:
4+
5+
animal_id=0
6+
def__init__(self,name,id):
7+
print("This is animal...")
8+
self.__name=name
9+
self.animal_id=id
10+
11+
defspeak(self):
12+
print("Animal {} with id {} speaks ..."
13+
.format(self.__name,self.animal_id))
14+
15+
16+
classDog(Animal):
17+
18+
def__init__(self,name,id_):
19+
super().__init__("Dog",id_)
20+
print("This is Dog..")
21+
self.__name=name
22+
23+
defspeak(self):
24+
print("Dog with name '{}' and with id {} barks ..."
25+
.format(self.__name,self.animal_id))
26+
27+
28+
d=Dog("Tobo",1)
29+
d.speak()
30+
print(d.__dict__)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file gives demo about multilevel inheritance
2+
3+
4+
classCompany:
5+
def__init__(self):
6+
print("This is Company ..")
7+
8+
defshow(self):
9+
print("We manufactures vehicles ..")
10+
11+
12+
classBikeCompany(Company):
13+
14+
def__init__(self):
15+
super().__init__()
16+
print("This is BikeCompany ..")
17+
18+
defshow(self):
19+
super().show()
20+
print("We manufactures bikes ..")
21+
22+
23+
classCarCompany(Company):
24+
25+
def__init__(self):
26+
super().__init__()
27+
print("This is CarCompany ..")
28+
29+
defshow(self):
30+
super().show()
31+
print("We manufactures cars ..")
32+
33+
34+
classBusCompany(Company):
35+
36+
def__init__(self):
37+
super().__init__()
38+
print("This is BusCompany ..")
39+
40+
defshow(self):
41+
super().show()
42+
print("We manufactures buses ..")
43+
44+
45+
classHonda(BusCompany,CarCompany,BikeCompany):
46+
47+
def__init__(self):
48+
super().__init__()
49+
print("This is Honda company ..")
50+
51+
defshow(self):
52+
super().show()
53+
print("We are Honda company")
54+
55+
56+
h1=Honda()
57+
h1.show()
58+
59+
print(h1.__class__.__mro__)
60+
61+
62+
63+
64+
65+
66+

‎concepts/PythonDemo09_Polymorphism.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
classPerson:
2+
3+
def__init__(self,name_="",id_=0):
4+
self.name=name_
5+
self.id=id_
6+
7+
def__str__(self):
8+
return"Person [ name = {} , id = {} ]".format(self.name,self.id)
9+
10+
defshow(self):
11+
print(self)
12+
print("*"*50)
13+
14+
15+
classStudent(Person):
16+
def__init__(self,name_="",id_=0,std_=""):
17+
super().__init__(name_,id_)
18+
self.std=std_
19+
20+
def__str__(self):
21+
return"Student [ name = {} , id = {}, std = {} ]".format(self.name,self.id,self.std)
22+
23+
defshow(self):
24+
print(self)
25+
print("*"*50)
26+
27+
28+
classEmployee(Person):
29+
def__init__(self,name_="",id_=0,salary=0):
30+
super().__init__(name_,id_)
31+
self.salary=salary
32+
33+
def__str__(self):
34+
return"Employee [ name = {} , id = {}, salary = {} ]".format(self.name,self.id,self.salary)
35+
36+
defshow(self):
37+
print(self)
38+
print("*"*50)
39+
40+
41+
p=Person("Rohit",1)
42+
s=Student("Rohit",1,"12th")
43+
e=Employee("Rohit",1,2000)
44+
45+
forxin (p,s,e):
46+
x.show()
47+

‎concepts/PythonDemo10_Abstraction.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file gives demo about abstraction
2+
3+
fromabcimportABC
4+
5+
6+
classShape(ABC):
7+
defdraw(self):
8+
pass
9+
10+
defshow(self,shape_name=''):
11+
print("This is {} shape".format(shape_name))
12+
13+
14+
classTriangleShape(Shape):
15+
16+
def__init__(self,shape_name="Triangle"):
17+
self.shapeName=shape_name
18+
19+
defdraw(self,a=0,b=0,c=0):
20+
print("Triagle[side1={}, side2={}, side3={}]".format(a,b,c))
21+
print("*"*50)
22+
23+
24+
classRectangleShape(Shape):
25+
26+
def__init__(self,shape_name="Rectangle"):
27+
self.shapeName=shape_name
28+
29+
defdraw(self,length=0,breadth=0):
30+
print("Rectangle[length={}, breadth={}".format(length,breadth))
31+
print("*"*50)
32+
33+
34+
s1=TriangleShape()
35+
s2=RectangleShape()
36+
37+
forsin [s1,s2]:
38+
s.show(s.shapeName)
39+
ifisinstance(s,TriangleShape):
40+
s.draw(10,20,30)
41+
else:
42+
s.draw(15,25)
43+

‎concepts/Sample.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classBaseClass:
2+
defcall_me(self):
3+
print("Base Class Method")
4+
5+
classLeftSubclass(BaseClass):
6+
defcall_me(self):
7+
super().call_me()
8+
print("Left Subclass Method")
9+
10+
classRightSubclass(BaseClass):
11+
defcall_me(self):
12+
super().call_me()
13+
print("Right Subclass Method")
14+
15+
classSubclass(LeftSubclass,RightSubclass):
16+
defcall_me(self):
17+
super().call_me()
18+
print("Subclass Method")
19+
20+
subClass=Subclass()
21+
print(subClass.__class__.__mro__)
22+
subClass.call_me()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp