Created
January 31, 2019 17:40
-
-
Save MarketaP/b5607f1998c8b773820d95a8cb351dec to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jan 30 17:12:45 2019 | |
@author: akilic3 | |
""" | |
#FIRST method | |
class NRES898(): | |
pass | |
#Class is basically creating bueprint for instances | |
#Create instances of the class | |
student1= NRES898 () | |
student2= NRES898 () | |
#each instance contains data | |
student1.first = "Reid" | |
student1.last = "Stagemeyer" | |
student1.department = "CompSci" | |
student2.first = "Jessica" | |
student2.last = "Dickinson" | |
student2.department = "NRCS" | |
""" | |
(1) Both of these are NRES898 objects and (2) they both are unique and | |
(3) they both have a different location in memory. | |
""" | |
print (student1.first) | |
print (student2.department) | |
#SECOND method | |
""" | |
Inside NRES898 class, we will create a "init" method within a class. | |
The methods receive instance as the first argument automatically. | |
By convention, we will call instance as “self” | |
Init method takes instances that we call “self” and then takes first, last, | |
department as arguments. | |
""" | |
class NRES898(): | |
pass | |
def __init__(self, first, last, department): | |
#Within our "init" method, we are going to set all those instance variables. | |
self.first = first | |
self.last = last | |
self.department = department | |
self.email = first + '.'+ last + "@unl.edu" | |
student1 = NRES898('Reid', 'Stagemeyer', 'CompSci') | |
student2 = NRES898('Jessica', 'Dickinson', 'NRCS') | |
student3 = NRES898('Mitchell', 'Maguire', 'BSE') | |
""" | |
When we create NRES898 down there, instance is passed automatically. | |
(a) we can leave off “self”. | |
(b) We only need to provide names and department. . | |
""" | |
def fullname(self): | |
return "{} {}".format(student1.first, student1.last) | |
#student1 = NRES898() | |
print (fullname(student1) ) | |
def fullname_dept_email(self): | |
return "Name: {} {} Dept: {} Email: {}".format( | |
student1.first, student1.last, student1.department, student1.email | |
) | |
print (fullname_dept_email(student1)) | |
print (NRES898.fullname_depth_email(student1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment