-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
class variable and instance variable
- Loading branch information
Showing
4 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# list search using in and ternary operator | ||
# made by : rakesh kumar | ||
# made by : rakesh kumar sharma | ||
|
||
a=[1,2,3,4,5,6,7,8,9] | ||
print( 5 in a and '5 is available in list ' or 'not found') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Example of class variable | ||
|
||
|
||
class student(): | ||
name = "rakesh" | ||
website ="binarynote.com" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
class student(): | ||
name="" | ||
website="" | ||
expertise="" | ||
|
||
def __init__(self): | ||
self.name ="swarnima" | ||
self.website = "http://www.swarnima.com" | ||
self.expertise ="Django Specialist" | ||
|
||
def showData(self): | ||
print("Name : ",self.name) | ||
print("website : ", self.website) | ||
print("Expertise :", self.expertise,"\n") | ||
class student: | ||
def __init__(self,name,website,expertise): | ||
self.name = name | ||
self.website = website | ||
self.expertise = expertise | ||
|
||
def showdata(self): | ||
return 'Name : {} \nWebsite: {} \nExpertise :{}'.format(self.name,self.website,self.expertise) | ||
#object creation | ||
# | ||
|
||
s1 = student() #calling constructor | ||
s1.showData() | ||
s1 = student('rakehs','https://bianrynote.com','Django Specilist') #calling constructor | ||
print(s1.showdata()) | ||
|
||
#calling function using class itself and passing object as its parameter | ||
print(student.showdata(s1)) |