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 […]

Python Operators: Arithmetic, Comparison, Logical and More - Python with AI tutorial chapter 12
Python

Python Operators: Arithmetic, Comparison, Logical and More

Python operators are the symbols that combine values into expressions: + to add, == to compare, and to join conditions, in to test membership. This chapter walks through every operator group in Python, from arithmetic to bitwise, and finishes with the precedence rules that decide which part of an expression runs first. Arithmetic operators The […]

Python Iterators and Generators: iter(), next() and yield - Python with AI tutorial chapter 34
Python

Python Iterators and Generators: iter(), next() and yield

Python iterators and generators are the machinery behind every for loop. An iterator is an object that hands out one value at a time through next(). A generator is the easiest way to build one: a function that uses yield instead of return, producing values lazily so you can process millions of rows without loading […]

Python Data Types: str, int, float, bool, list and More - Python with AI tutorial chapter 6
Python

Python Data Types: str, int, float, bool, list and More

Python data types describe what kind of value a variable holds: text (str), whole numbers (int), decimals (float), true/false flags (bool), ordered collections (list, tuple), key-value pairs (dict) and unique items (set). Knowing the type tells you what operations are allowed. This chapter introduces each built-in type with a business example. The built-in data types […]

Python Functions: def, Arguments, Return and *args - Python with AI tutorial chapter 20
Python

Python Functions: def, Arguments, Return and *args

A Python function is a named, reusable block of code that performs one task. You define it once with the def keyword, give it inputs called parameters, and call it as many times as you need. Functions return results with return, accept optional and keyword arguments, and can take any number of values through *args […]