xxxxxxxxxx
<div class="alert" role="alert">Warning! I'm missing something</div>
xxxxxxxxxx
class Planet:
def __init__(self, name, radius, gravity, system):
self.name = name
self.radius = radius
self.gravity = gravity
self.system = system
def orbit(self):
return f'{self.name} is orbiting in the {self.system}'
alphax123 = Planet('alphax123', 300000, 8, 'Naboo System')
print(f'Name: {alphax123.name}')
print(f'Radius: {alphax123.radius}')
print(f'Gravity: {alphax123.gravity}')
print(f'System: {alphax123.orbit}')
xxxxxxxxxx
# class
class Enum:
Tim, Bill, Joe = range(1,4)
print(Enum.Tim == 1) # return True
xxxxxxxxxx
class Person:
def __init__(self, name, sex, profession):
# data members (instance variables)
self.name = name
self.sex = sex
self.profession = profession
# Behavior (instance methods)
def show(self):
print('Name:', self.name, 'Sex:', self.sex, 'Profession:', self.profession)
# Behavior (instance methods)
def work(self):
print(self.name, 'working as a', self.profession)
xxxxxxxxxx
/* Any Element With Class Title */
.title {
}
/* Any element with id nav */
#nav {
}
/* any div element */
div {
}
/* any element h2 */
h2 {
}
xxxxxxxxxx
# Example of defining a class in Python
class MyClass:
def __init__(self, attribute):
self.attribute = attribute
def my_method(self):
print("Hello, world!")
# Creating an instance of the class
my_object = MyClass("example")
# Accessing the attribute and calling the method
print(my_object.attribute)
my_object.my_method()