File tree Expand file tree Collapse file tree 1 file changed +34
-4
lines changed Expand file tree Collapse file tree 1 file changed +34
-4
lines changed Original file line number Diff line number Diff line change 1
- class Person :
1
+ #A simple program to under the concept of class and object in python3
2
+ class BookStore :
3
+ noOfBooks = 0
4
+
5
+ def __init__ (self , title , author ):
6
+ self .title = title
7
+ self .author = author
8
+ BookStore .noOfBooks += 1
9
+
10
+ def bookInfo (self ):
11
+ print ("Book title:" , self .title )
12
+ print ("Book author:" , self .author ,"\n " )
13
+
14
+ # Create a virtual book store
15
+ b1 = BookStore ("Great Expectations" , "Charles Dickens" )
16
+ b2 = BookStore ("War and Peace" , "Leo Tolstoy" )
17
+ b3 = BookStore ("Middlemarch" , "George Eliot" )
18
+
19
+ # call member functions for each object
20
+ b1 .bookInfo ()
21
+ b2 .bookInfo ()
22
+ b3 .bookInfo ()
2
23
3
- age = 18
24
+ print ( "BookStore.noOfBooks:" , BookStore . noOfBooks )
4
25
5
- def name (self , name ):
6
- return list (name )
26
+ ##OUTPUT :
27
+ #Book title: Great Expectations
28
+ #Book author: Charles Dickens
29
+
30
+ #Book title: War and Peace
31
+ #Book author: Leo Tolstoy
32
+
33
+ #Book title: Middlemarch
34
+ #Book author: George Eliot
35
+
36
+ #BookStore.noOfBooks: 3
You can’t perform that action at this time.
0 commit comments