DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

Classes / Objects — Example 106

Quick explanation + ready code for: Classes / Objects.

Python Classes / Objects Back to examples
Back to language
Syntax: Classes / Objects in Python. ID: #106

Code

class User:
  def __init__(self,name):
    self.name=name
  def hi(self):
    return "Hi " + self.name
print(User("A").hi())

Notes

You can copy this snippet and adapt it. For advanced, add real-world inputs, edge cases, and tests.