Python Classe & Object
Python Tutorial » Python Classe & Object
Python is an object oriented programming language. An object is simply a collection of data (variables) and methods (functions) that act on those data.
Create a Class
Example: Create a class named My_Class, with a property named y:
Output:
<class '__main__.My_Class'>
class My_Class:
y = 101224
print(My_Class)
y = 101224
print(My_Class)
Output:
<class '__main__.My_Class'>
Create Object
Example: Create an object named name_1, and print the value of z:
Output:
127
class My_Class_object:
z = 127
name_1 = My_Class_object()
print(name_1.z)
z = 127
name_1 = My_Class_object()
print(name_1.z)
Output:
127
__init__() Function - example
This type of function "__init__()" (without quotes) is called constructors in Object Oriented Programming (OOP). We use it to initialize all the variables.
Example:
London
12000458
class town:
def __init__(self, name, population):
self.name = name
self.population = population
data1 = town("London", 12000458)
print(data1.name)
print(data1.population)
Output: def __init__(self, name, population):
self.name = name
self.population = population
data1 = town("London", 12000458)
print(data1.name)
print(data1.population)
London
12000458
python object is not subscriptable, oriented, to json, type, to string, oriented programming, is not iterable, has no attribute, to dict, class
python classes explained, and objects, attributes, heritage, inheritance,
Python Classes & Objects - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.