{"id":23272377,"url":"https://github.com/letsdeepchat/our_imp_progg","last_synced_at":"2025-04-06T09:53:02.429Z","repository":{"id":153852875,"uuid":"219479782","full_name":"letsdeepchat/Our_Imp_PROGG","owner":"letsdeepchat","description":"Hacker_rank_Interview","archived":false,"fork":false,"pushed_at":"2020-02-18T17:46:15.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T15:41:18.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/letsdeepchat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-04T10:55:20.000Z","updated_at":"2020-02-18T17:46:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"e09d26c8-8169-4e2e-b808-96a847b126e6","html_url":"https://github.com/letsdeepchat/Our_Imp_PROGG","commit_stats":null,"previous_names":["letsdeepchat/our_imp_progg"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsdeepchat%2FOur_Imp_PROGG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsdeepchat%2FOur_Imp_PROGG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsdeepchat%2FOur_Imp_PROGG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsdeepchat%2FOur_Imp_PROGG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letsdeepchat","download_url":"https://codeload.github.com/letsdeepchat/Our_Imp_PROGG/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247463933,"owners_count":20942950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-19T19:15:13.922Z","updated_at":"2025-04-06T09:53:02.405Z","avatar_url":"https://github.com/letsdeepchat.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"Classes and Objects I\nTUTORIAL\nPython Classes and Methods\nPython is an “object-oriented programming language.” This means that almost all the code is implemented using a special construct called classes. Programmers use classes to keep related things together. This is done using the keyword “class,” which is a grouping of object-oriented constructs.\n\nBy the end of this tutorial you will be able to:\n\nDefine what is a class\nDescribe how to create a class\nDefine what is a method\nDescribe how to do object instantiation\nDescribe how to create instance attributes in Python\nWhat is a class?\nA class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.\n\nAn object is created using the constructor of the class. This object will then be called the instance of the class. In Python we create instances in the following manner\n\nInstance = class(arguments)\nHow to create a class\nThe simplest class can be created using the class keyword. For example, let's create a simple, empty class with no functionalities.\n\n\u003e\u003e\u003e class Snake:\n...     pass\n... \n\u003e\u003e\u003e snake = Snake()\n\u003e\u003e\u003e print(snake)\n\u003c__main__.Snake object at 0x7f315c573550\u003e\nAttributes and Methods in class:\nA class by itself is of no use unless there is some functionality associated with it. Functionalities are defined by setting attributes, which act as containers for data and functions related to those attributes. Those functions are called methods.\n\nAttributes:\nYou can define the following class with the name Snake. This class will have an attribute name.\n\n\u003e\u003e\u003e class Snake:\n...     name = \"python\" # set an attribute `name` of the class\n...\nYou can assign the class to a variable. This is called object instantiation. You will then be able to access the attributes that are present inside the class using the dot . operator. For example, in the Snake example, you can access the attribute name of the class Snake.\n\n\u003e\u003e\u003e # instantiate the class Snake and assign it to variable snake\n\u003e\u003e\u003e snake = Snake()\n\n\u003e\u003e\u003e # access the class attribute name inside the class Snake.\n\u003e\u003e\u003e print(snake.name)\npython\nMethods\nOnce there are attributes that “belong” to the class, you can define functions that will access the class attribute. These functions are called methods. When you define methods, you will need to always provide the first argument to the method with a self keyword.\n\nFor example, you can define a class Snake, which has one attribute name and one method change_name. The method change name will take in an argument new_name along with the keyword self.\n\n\u003e\u003e\u003e class Snake:\n...     name = \"python\"\n...     \n...     def change_name(self, new_name): # note that the first argument is self\n...         self.name = new_name # access the class attribute with the self keyword\n...\nNow, you can instantiate this class Snake with a variable snake and then change the name with the method change_name.\n\n\u003e\u003e\u003e # instantiate the class\n\u003e\u003e\u003e snake = Snake()\n\n\u003e\u003e\u003e # print the current object name \n\u003e\u003e\u003e print(snake.name)\npython\n\n\u003e\u003e\u003e # change the name using the change_name method\n\u003e\u003e\u003e snake.change_name(\"anaconda\")\n\u003e\u003e\u003e print(snake.name)\nanaconda\nInstance attributes in python and the init method\nYou can also provide the values for the attributes at runtime. This is done by defining the attributes inside the init method. The following example illustrates this.\n\nclass Snake:\n\n    def __init__(self, name):\n        self.name = name\n\n    def change_name(self, new_name):\n        self.name = new_name\nNow you can directly define separate attribute values for separate objects. For example,\n\n\u003e\u003e\u003e # two variables are instantiated\n\u003e\u003e\u003e python = Snake(\"python\")\n\u003e\u003e\u003e anaconda = Snake(\"anaconda\")\n\n\u003e\u003e\u003e # print the names of the two variables\n\u003e\u003e\u003e print(python.name)\npython\n\u003e\u003e\u003e print(anaconda.name)\nanaconda\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsdeepchat%2Four_imp_progg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletsdeepchat%2Four_imp_progg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsdeepchat%2Four_imp_progg/lists"}