Skip to content

Rofeeah/make-a-profile-python-oop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Make a Profile class

Run on Repl.it

The goal:

Today, we're learning about creating instances (individual versions) of classes (Types that we use as blueprints). This will unlock a lot of power for us later, but getting a class off the ground takes a lot of work.

Our end goal is to be able to create profiles for individual people, and then access and change the data we have about those people.

Write an __init__ method

Ultimately, we want to be able to create new profiles in our test.py file with lines of code that look like this:

first_profile = profile_class.Profile("Nicki")
second_profile = profile_class.Profile("Sarah")

In order for that code to work, you'll need to write an initializer method in our profile_class.py file for the Profile class - otherwise, Python has no idea what to do with the string "Nicki" when you call Profile("Nicki"). Try to do it on your own, but if you forget, click the dropdown to see one way to do it.

Click to see an example of an __init__ method
class Profile:
  def __init__(self, name):
    self.name = name

When you think you're ready to test your code, enter the command `python test.py` in terminal.

Extensions

Your user profile currently only has a name. What other traits, attributes, or information might a user have on your site?

This is a pretty open-ended lab, so if you decide your social media site is a dating app for dogs, fine - your users might have some instance variables like breed and fur_color. You might go a totally different direction and create a college-matching application, in which case users might have traits like gpa and grade. The direction you go with this is up to you, but please make it a goal to include at least one instance variable for each of these four major datatypes:

  • String
  • Integer
  • Float
  • Boolean (True or False)

Be sure to initialize at least three unique users for your site. We already have Nicki and Sarah above, but you'll need to make at least one more.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%