THE WORLD'S LARGEST WEB DEVELOPER SITE

Python class Keyword

❮ Python Keywords


Example

Create a class named "Person":

class Person:
  name = "John"
  age = 36
Run example »

Definition and Usage

The class keyword is used to create a class.

A class is like an object constructor. See the example below to see how we can use it to create an object.


More Examples

Example

Create an object named p1, using the class from the example above:

p1 = Person()

print(p1.name)
Run example »

Related Pages

Read more about classes and objects in our Python Classes/Objects Tutorial.


❮ Python Keywords