Code
# Create a class Square
class Square():
def __init__(self, length):
self.length = length
def area(self):
return self.length*self.length
def perimiter(self):
return self.length*4
In this chapter we’ll cover some of the basics of Python. This will include using Python as a calculator, variables in Python, loops, conditionals, and functions. This will help form a basic understanding of the fundamentals of programming with Python’s syntax
A Class in Python acts as a “blueprint” for creating objects. They are extremely useful for the reusability and organization of code.
An instance is an object that belongs to a class.
Let’s consider the following example
In this case we have created a class
2+2
---
title: "Introduction to Python"
format: html
---
In this chapter we'll cover some of the basics of Python. This will include using Python as a calculator, variables in Python, loops, conditionals, and functions. This will help form a basic understanding of the fundamentals of programming with Python's syntax
## Variables and Assignments
## Loops in Python
## Conditionals
## Functions
## Classes in Python
A **Class** in Python acts as a "blueprint" for creating objects. They are extremely useful for the reusability and organization of code.
An **instance** is an object that belongs to a class.
Let's consider the following example
```{python}
# Create a class Square
class Square():
def __init__(self, length):
self.length = length
def area(self):
return self.length*self.length
def perimiter(self):
return self.length*4
```
In this case we have created a `class`
```{python}
square1 = Square(23)
square2 = Square(23.123)
```
```{python}
square1.length
```
```{python}
square1.perimiter()
```
```{python}
square1.area()
```
```{julia}
2+2
```