0% found this document useful (0 votes)
24 views5 pages

Data Types Web Notes PDF

The document provides an overview of data types in Python, including text, numeric, sequence, mapping, set, binary, boolean, and NoneType, along with their mutability. It covers operations on text strings, binary data handling, file I/O, database connectivity with SQLite and MongoDB, and web concepts using Flask and REST APIs. Additionally, it outlines advanced use cases such as data pipelines, web scraping, and machine learning model serving.

Uploaded by

priyangas100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

Data Types Web Notes PDF

The document provides an overview of data types in Python, including text, numeric, sequence, mapping, set, binary, boolean, and NoneType, along with their mutability. It covers operations on text strings, binary data handling, file I/O, database connectivity with SQLite and MongoDB, and web concepts using Flask and REST APIs. Additionally, it outlines advanced use cases such as data pipelines, web scraping, and machine learning model serving.

Uploaded by

priyangas100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Types and Web in Python – M.Sc.

Computer
Science
1. DATA TYPES IN PYTHON
Definition: A data type is a classification specifying the type of value a variable can hold, how it is stored,
and operations allowed.

Categories

Category Definition Example

Text Sequence of characters str

Numeric Numbers used in arithmetic int, float, complex

Sequence Ordered collections list, tuple, range

Mapping Key-value pair collections dict

Set Unique unordered elements set, frozenset

Binary Raw byte data bytes, bytearray, memoryview

Boolean True or False values bool

NoneType Represents absence of value None

Key Notes

• Mutable: list, dict, set, bytearray


• Immutable: str, tuple, frozenset, int, float, complex

2. TEXT STRINGS
Definition: A string is a sequence of Unicode characters enclosed in quotes.

Operations

• Indexing, slicing, concatenation, repetition


• Encoding/Decoding for storage/transfer

s = "Python Programming"
print(s[0])

1
print(s[0:6])
print(s*2)

Advanced Methods

text = " Data Science with Python "


print(text.strip())
print(text.upper())
print(text.lower())
print(text.replace("Python", "AI"))
words = text.split()
print("-".join(words))

Formatting

name = "Priya"
age = 23
print(f"My name is {name} and I am {age} years old.")

3. BINARY DATA
Definition: Data stored in bytes for multimedia, encryption, and low-level processing.

b = b"Hello"
ba = bytearray(b)
ba[0] = 72
print(ba)

Reading/Writing Binary Files:

with open("image.jpg", "rb") as f:


data = f.read()
with open("copy.jpg", "wb") as f:
f.write(data)

4. STORING AND RETRIEVING DATA


Definition: Saving data to files/databases and retrieving for processing.

2
File I/O

with open("sample.txt", "w") as f:


f.write("Hello Python")

Structured Files

CSV: Tabular data JSON: Hierarchical key-value data Pickle: Python object serialization

5. DATABASE CONNECTIVITY

Relational Database (SQLite)

import sqlite3
conn = sqlite3.connect("college.db")
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY, name
TEXT, marks INTEGER)')
cursor.execute("INSERT INTO student(name,marks) VALUES(?,?)", ("Priya",95))
conn.commit()

NoSQL Database (MongoDB)

from pymongo import MongoClient


client = MongoClient()
db = client["university"]
db.students.insert_one({"name":"Anu", "marks":90})

6. WEB CONCEPTS

Web Clients

import requests
r = requests.get("https://jsonplaceholder.typicode.com/posts/1")
print(r.json())

3
Web Servers (Flask)

from flask import Flask


app = Flask(__name__)
@app.route("/")
def home():
return "Hello Flask"
app.run(debug=True)

Web Services (REST API)

from flask import Flask, jsonify


app = Flask(__name__)
@app.route('/api/data')
def data():
return jsonify({"course":"MSc CS","subject":"Python"})

Web Automation

from selenium import webdriver


driver = webdriver.Chrome()
driver.get("https://google.com")
print(driver.title)
driver.quit()

7. ADVANCED USE CASES


1. Data Pipeline: CSV → Clean → MongoDB → Flask API → Dashboard
2. Web Scraping + Storage: Scrape → SQLite → Email alerts
3. Machine Learning: Pickle models → Serve via Flask API

8. SUMMARY TABLE

Concept Definition Module/Tool Use Case

Text Strings Sequence of Unicode characters str NLP, reports

Binary Data Sequence of bytes bytes, bytearray Media processing

File I/O Read/write files open(), csv, json Data persistence

4
Concept Definition Module/Tool Use Case

Structured
Serialize Python objects pickle, h5py ML model storage
Binary

Transactional
Relational DB Tables with relationships sqlite3, PostgreSQL
storage

NoSQL DB Schema-less storage pymongo, MongoDB Web apps, analytics

REST API
Web Client Sends HTTP requests requests
consumption

Web Server Responds to HTTP requests Flask, Django Web apps

Machine-to-machine data
Web Service Flask API, FastAPI REST APIs
exchange

BeautifulSoup,
Automation Automates web tasks Scraping/testing
Selenium

---

End of Notes.

You might also like