BP101T • Unit 1: Basic String Operation and Manipulation Techniques & Python Libraries
TOPIC 01

Basic String Operations & Concatenation

Basic string operation and manipulation techniques:

A string in Python is a sequence of characters (letters, numbers, symbols, or spaces) enclosed inside single (' '), double (" "), or triple (''' ''') quotes.

Basic String Operations:

Joining two or more strings end-to-end into a single string.

Ex:
first = "Hello"
second = "Python"
result = first + " " + second
print(result)
output:
Hello Python
Python String Operations and Manipulation Visual Cheat Sheet
Figure 1.3: Visual cheat sheet for Python string operations and manipulation techniques.
✓
Key Takeaway• Quick Recap

A string is an immutable sequence of characters enclosed in quotes. Joining multiple strings is performed using the '+' operator.

TOPIC 02

String Repetition (*)

Repetition (*):

Repeating a string a specified number of times.

Example:
word = "Hi! "
print(word * 3)
output:
Hi! Hi! Hi!
✓
Key Takeaway• Quick Recap

The '*' operator repeats a string a specified number of times efficiently without writing manual loops.

TOPIC 03

String Length Calculation (len())

Length (len()):

Returns the total number of characters in a string, including spaces.

Example:
text = "Python 101"
print(len(text))
output:
10
✓
Key Takeaway• Quick Recap

The len() function returns the total number of characters in a string, counting all spaces, letters, and punctuation.

TOPIC 04

String Indexing and Slicing Techniques

Indexing and Slicing

Accessing a single character using its position. Forward indexing starts at 0, while negative indexing starts at -1 from the end.

Indexing Example:
word = "PYTHON"
print(word[0])# First character
print(word[-1])# Last character
output:
P
N

Slicing:

Extracting a substring (portion of a string) from start index up to stop - 1.

Slicing Example:
text = "Programming"
print(text[0:7])# Characters from index 0 to 6
print(text[:4])# From start up to index 3
print(text[::-1])# Reverses the entire string
output:
Program
Prog
gnimmargorP
✓
Key Takeaway• Quick Recap

Forward indexing starts at 0, reverse indexing at -1. Slicing with [start:stop:step] extracts substrings without mutating the original string.

TOPIC 05

String Manipulation Methods (upper, lower, strip, replace, split, join)

String Manipulation Methods

Changing Case (upper(), lower(), title()):

Converts characters into uppercase, lowercase, or capitalizes the first letter of each word.

Ex:
msg = "python programming"
print(msg.upper())
print(msg.title())
output:
PYTHON PROGRAMMING
Python Programming

Removing Whitespace (strip()):

Removes extra spaces (or specified characters) from the beginning and end of a string.

Ex:
raw_input = " admin@gmail.com "
print(raw_input.strip())
output:
admin@gmail.com

Replacing Text (replace(old, new)):

Replaces all occurrences of a specified substring with another substring.

Ex:
text = "I like Java"
print(text.replace("Java","Python"))
output:
I like Python

Splitting and Joining (split() & join()):

split() breaks a string into a list of substrings based on a separator, while join() combines a list of strings back into a single string.

Ex:
data = "apple,banana,cherry"
fruits = data.split(",")# Splits into a list
print(fruits)

joined = " - ".join(fruits)# Joins list items into a string
print(joined)
output:
['apple', 'banana', 'cherry']
apple - banana – cherry
✓
Key Takeaway• Quick Recap

Built-in string methods like upper(), lower(), strip(), and split() return newly constructed string objects.

TOPIC 06

Python Standard Library Modules (math, os, datetime, sys)

Python Standard Library

It is a preinstalled default package that comes with Python, which can loaded using the import keyword.

Python Standard Libraries Cheat Sheet
Figure 1.4: Overview of Python Standard Library built-in modules.

math: Provides mathematical functions and constants like square roots, powers, and pi.

Ex:
import math
print(math.sqrt(16))# Output: 4.0

os: Interacts with your operating system to manage folders, file paths, and directories.

Ex:
import os
print(os.getcwd())# Output: Current folder path

datetime: Works with current dates, times, and calendar formatting.

Ex:
import datetime
print(datetime.date.today())# Output: 2026-11-24

sys: Accesses Python interpreter details and system-level settings.

Ex:
import sys
print(sys.version)# Output: Installed Python version
✓
Key Takeaway• Quick Recap

The Standard Library comes preinstalled with Python, offering battle-tested tools ready to use via the 'import' keyword.

TOPIC 07

Third-Party Libraries (NumPy, Pandas, Matplotlib, Flask, OpenCV)

Third-party libraries:

Third-party libraries are external packages and tools which is made by the global Python developer community. They are hosted on PyPI (Python Package Index) and installed using the pip install package_name command before importing them into your code.

Python Third-Party Libraries Cheat Sheet
Figure 1.5: Essential third-party libraries in the Python ecosystem.

Ex:

NumPy (Numerical Python): Used for fast mathematical operations, multi-dimensional arrays, and matrix calculations.

import numpyas np
arr = np.array([1, 2, 3])
print(arr * 2)# Output: [2 4 6]

Pandas: Used for data analysis, cleaning, and manipulating tabular data (like Excel sheets or CSV files) using DataFrames.

import pandasas pd
df = pd.DataFrame({"Name": ["Aman", "Riya"], "Marks": [85, 92]})
print(df)

Matplotlib: Used for creating static, animated, and interactive charts, graphs, and plots for data visualization.

import matplotlib.pyplotas plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()

Flask / Django: Web development frameworks used to build websites, web applications, and backend APIs.

from flask import Flask
app = Flask(__name__)
print("Flask app initialized:", app.name)

OpenCV (cv2): Used for computer vision tasks like image processing, face detection, and video analysis.

import cv2
img = cv2.imread("photo.jpg")
✓
Key Takeaway• Quick Recap

Third-party packages are created by the global Python community, hosted on PyPI, and installed using pip before importing.

TOPIC 08

Standard Library vs. Third-Party Library Comparison

Standard Library vs. Third-Party Library

FeatureStandard LibraryThird-Party Library
InstallationAlready pre-installed with Python.Must be installed separately via pip install.
UsageReady to import immediately.import works only after installation.
Examplesmath, random, datetime, osnumpy, pandas, matplotlib, requests
✓
Key Takeaway• Quick Recap

Standard libraries are built-in and require no internet download; third-party packages must be downloaded from PyPI via pip install.

TOPIC 09

Installing and Uninstalling Libraries with pip

Installing and uninstalling libraries:

Python uses pip (Preferred Installer Program), It is a package manager, to download, install, update, and remove third-party libraries from the Python Package Index (PyPI).

Installing and Uninstalling Python Libraries with pip
Figure 1.6: Installing and uninstalling Python libraries with pip command sheet.

Installing a Library

Downloads and adds a third-party library and its required dependencies to your Python environment so you can import it in your code.

Ex:
pip install package_name
pip install numpy

Uninstalling a Library

Completely removes a previously installed third-party library from your Python environment to free up space.

Ex:
pip uninstall package_name
pip uninstall numpy
✓
Key Takeaway• Quick Recap

pip install package_name adds packages to your environment, while pip uninstall removes them to free up disk space.