Python Web Scraping with requests and BeautifulSoup - Python with AI tutorial chapter 36
Python

Python Web Scraping with requests and BeautifulSoup

Python web scraping means downloading a web page with requests and pulling the data you need out of its HTML with BeautifulSoup. This chapter scrapes book titles, prices and ratings from a practice site, follows pagination, saves the result to CSV and explains the rules (robots.txt, terms of use, rate limits) that keep scraping legal […]

Python Type Casting: int(), float() and str() Explained - Python with AI tutorial chapter 8
Python

Python Type Casting: int(), float() and str() Explained

Python type casting means converting a value from one data type to another, for example turning the text “250” into the integer 250 so you can add to it. The main casting functions are int(), float(), str() and bool(), plus list(), tuple(), set() and dict() for collections. This chapter shows when each one is needed […]

Python Try...Except: Handle Errors and Exceptions - Python with AI tutorial chapter 23
Python

Python Try…Except: Handle Errors and Exceptions

Python try except is the mechanism for handling errors without crashing your program. Code that might fail goes in a try block; if an exception occurs, Python jumps to the matching except block instead of stopping. Optional else and finally clauses run when no error occurred and when the block finishes, respectively. Why exceptions matter […]

Python Lists: Create, Access, Add, Remove and Sort Items - Python with AI tutorial chapter 13
Python

Python Lists: Create, Access, Add, Remove and Sort Items

Python lists are ordered, changeable collections written in square brackets, such as [“Laptop”, “Monitor”, “Mouse”]. They are the workhorse data structure of the language: a column of sales figures, a queue of tasks, the rows read from a CSV file. This chapter shows how to create Python lists and how to access, add, remove, sort […]

Python Scope: Local, Global and nonlocal Variables - Python with AI tutorial chapter 22
Python

Python Scope: Local, Global and nonlocal Variables

Python scope is the set of rules that decides where a variable can be seen and changed. A variable created inside a function has local scope and disappears when the function ends; a variable created at the top of a file has global scope. The global and nonlocal keywords let a function deliberately modify variables […]

Build a Chatbot in Python with an AI API Step by Step - Python with AI tutorial chapter 44
Python

Build a Chatbot in Python with an AI API Step by Step

A chatbot in Python is a loop that reads what the user types, sends the whole conversation so far to an AI API, prints the reply and repeats. The model itself remembers nothing between calls, so your code keeps the history. This chapter builds a terminal chatbot with a system prompt, then moves the same […]

Python Requests: Call REST APIs and Handle JSON Responses - Python with AI tutorial chapter 35
Python

Python Requests: Call REST APIs and Handle JSON Responses

Python requests is the most popular library for talking to web services. With one line you can call a REST API, and with .json() you turn the response into Python dictionaries and lists. This chapter covers GET and POST calls, query parameters, headers, timeouts, error handling and how to pull live exchange rates into a […]

Python JSON: Parse, Create and Save JSON Data - Python with AI tutorial chapter 28
Python

Python JSON: Parse, Create and Save JSON Data

Python JSON handling lives in the built-in json module. JSON (JavaScript Object Notation) is the text format that web APIs, config files and AI services use to exchange data, and it maps almost one-to-one onto Python dictionaries and lists. Four functions do the work: loads and dumps for strings, load and dump for files. You […]

Python Numbers: int, float, complex and Math Operations - Python with AI tutorial chapter 7
Python

Python Numbers: int, float, complex and Math Operations

Python numbers come in three built-in types: int for whole numbers of any size, float for decimals and complex for numbers with an imaginary part. Python supports the usual arithmetic operators plus integer division, modulus and exponent, and the math and decimal modules extend them. This chapter covers each type and the operations you will […]

Python Lambda Functions: Syntax and Examples - Python with AI tutorial chapter 21
Python

Python Lambda Functions: Syntax, Examples and When to Use

A Python lambda function is a small anonymous function written in a single expression. It has no name and no def block, just the keyword lambda, its parameters, a colon and the value to return. Lambdas are most useful as short throwaway functions passed to sorted(), map(), filter() and similar tools. Lambda syntax The general […]