Skip to content

Python

  • High-level, interpreted language prized for simplicity, readability, and flexibility.
  • Commonly used for web development, data analysis, artificial intelligence, and scientific computing.
  • Uses indentation to denote blocks and supports object-oriented programming.

Python is a high-level, interpreted programming language that is widely used for web development, data analysis, artificial intelligence, and scientific computing. It is known for its simplicity, readability, flexibility, and a large active community of developers.

  • Python emphasizes readable, concise code and uses indentation to denote blocks of code, which helps visually distinguish different code blocks and improves readability.
  • The language supports object-oriented programming (OOP), allowing creation of objects that represent real-world entities with attributes and behavior.
  • The special method init is the constructor called when a new object is created and is used to set initial attribute values.
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
print(factorial(5))

In this code, the block of code inside the if statement is indented by four spaces, while the block of code inside the else statement is also indented by four spaces. This helps to visually distinguish the different blocks of code and makes the code easier to read and understand.

class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
print("Woof!")
dog1 = Dog("Fido", "Labrador")
dog2 = Dog("Buddy", "Poodle")
print(dog1.name)
print(dog2.breed)
dog1.bark()
dog2.bark()

In this code, the Dog class has two attributes (name and breed) and a method (bark). The init method, also known as the constructor, is called when a new Dog object is created and allows us to set the initial values for the object’s attributes. We can then create two Dog objects (dog1 and dog2) and access their attributes and call their methods.

  • Web development
  • Data analysis
  • Artificial intelligence
  • Scientific computing
  • Indentation is syntactically significant in Python; proper use of indentation helps distinguish code blocks and improves readability.
  • The init method is the constructor and runs when an object is created to initialize attribute values.
  • Object-oriented programming (OOP)
  • init (constructor)
  • Method
  • Attribute