Introduction to Python
Programming
Embark on a journey to master Python, a versatile and powerful
programming language. This presentation covers essential
concepts for beginners and data science enthusiasts alike.
by Aishu
Understanding Variables and Data Types
Variables Data Types Dynamic Typing
Named storage locations for Categorise data stored in Python variables can change
data. They hold various values. variables. Common types include type during execution, offering
integers, floats, strings, and flexibility.
booleans.
Variables are fundamental building blocks in Python, allowing you to store and manipulate information effectively.
Python Constants: Best Practices
Python lacks true constants. By convention, variables intended as constants are named using all uppercase letters.
Naming Convention Purpose
Use UPPER_CASE for constant names. Indicates values that should not change.
PI = 3.14159 MAX_CONNECTIONS = 100
While mutable, this convention signals their intended immutability to other developers.
Type Casting and Conversion
Type Casting
Explicitly changing a variable's data type. For example,
converting a string to an integer.
Built-in Functions
Use int(), float(), str() for conversions. Ensures data
compatibility for operations.
Data Integrity
Careful conversion prevents errors. Crucial for mathematical
operations or data validation.
Understanding type conversion is vital for robust Python programming and
data handling.
Controlling Program Flow:
Conditionals and Loops
If-Else Statements
Execute code blocks based on conditions. Enables decision-
making in programs.
For Loops
Iterate over sequences like lists or strings. Ideal for repetitive
tasks with known iterations.
While Loops
Repeat a block of code as long as a condition is true. Useful for
indefinite repetitions.
Conditional statements and loops are essential for creating dynamic and
efficient Python programs.
Python Collections: Lists, Tuples,
and Dictionaries
Lists Tuples
Ordered, mutable collections of items. Ordered, immutable collections. Useful
Ideal for dynamic data sets where for fixed data sets, such as coordinates
elements can change. or record entries.
Dictionaries
Unordered collections of key-value
pairs. Perfect for mapping unique keys
to corresponding values for quick
lookup.
These data structures offer flexible ways to organise and manage data in Python.
Object-Oriented Programming (OOP) in Python
Objects
Classes Instances of classes, real-world
Blueprints for creating objects. entities.
Message
Polymorphism Interactions between objects.
Objects taking many forms. Inheritance
Classes inheriting properties.
Encapsulation
Abstraction
Bundling data and methods.
Hiding complex details.
OOP principles enable modular, reusable, and scalable code development in Python.
Numpy Basics for Data Science
Numpy is crucial for numerical operations in Python, especially for large datasets. It provides efficient array objects.
Array Creation Array Operations
Create n-dimensional arrays using np.array(). Perform element-wise operations and mathematical
functions.
import numpy as nparr = np.array([1, 2, 3])
arr + 2np.sqrt(arr)
Numpy's performance benefits make it a cornerstone of scientific computing.
Pandas Basics for Data Science
Pandas is indispensable for data manipulation and analysis, offering powerful data structures like DataFrames.
DataFrame Creation Data Selection
Create tabular data structures from various sources. Access specific rows or columns easily using labels or
indices.
import pandas as pddata = {'col1': [1, 2],
'col2': [3, 4]}df = pd.DataFrame(data) df['col1']df.iloc[0]
Pandas streamlines data cleaning, transformation, and exploration for data scientists.