Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Python Basics

This page covers minimal, hands-on Python essentials for ML. It’s designed to be short intutibe and executable in the accompanying notebook notebooks/python_basics.ipynb.

Resources

Goal

What is python ?

Python is a high-level, general-purpose programming language known for its simple, readable syntax that emphasizes code clarity and allows developers to express concepts in fewer lines of code than many other languages

Key Features

Common Applications

with this, lets begins from variables,

Variables

variables are very basic elements and simple placeholders to hold some value(reference aswell) in python code or file. As the term says,the value can be changed by all possible programming logic or by direct assignment to the variable while running code.

In the below example, X holds the value 10, while fruits holds the reference of the List of fruits names.


# Variables Examples
x = 10 #Interger
pi = 3.14159 #Float
name = 'DataWizard' #String
is_working = True # Boolean
i = None # None type.
# List
fruits = ['apple', 'banana', 'cherry']

print(x, pi, name)

Data Types

Numeric Types

These types are used to store numeric values.


# Examples
x = 10 #Interger
pi = 3.14159 #Float
a = 2+3j # Complex Number

print(x, pi, name)

Sequence Types

These are ordered collections of items, where each item can be accessed by an index.


#  Examples
s = "Hello World"

# List
fruits = ['apple', 'banana', 'cherry']
# tuple
t = (1,2)
print(s,s[0])

Mapping Type


# Examples
m = {'a':1,'b':2}
print(m['a'])

Set Types

Boolean Type

Binary Types

None Type

Small NumPy demo

We’ll use NumPy for basic vector math. See the notebook for live execution.

import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(a + b)  # elementwise addition

Tiny Pandas example

import pandas as pd
df = pd.DataFrame({'feature': [1,2,3], 'target':[0,1,0]})
df

Where to run

Open notebooks/python_basics.ipynb locally or python data types. We’ll add Binder/Thebe badges later for live execution if you want that interactive route.