Python Fundamentals for Artificial Intelligence
Official Duration: 50 Hours · Variables, Operators, Flow of Control & Lists
1. Variables & Naming Rules
A variable is a named storage location in memory. In Python, variables are dynamically typed and created upon assignment.
- Names can contain letters, digits, and underscores (
_). - Names cannot begin with a digit (e.g.,
1scoreis invalid). - Names are case-sensitive (
Ageandageare distinct). - Reserved keywords (such as
if,for,class) cannot be used as variable names.
2. Operators in Python
Arithmetic Operators
- + (Addition), - (Subtraction)
- * (Multiplication), / (Float Division: 7/2 = 3.5)
- // (Floor Division: 7//2 = 3)
- % (Modulus Remainder: 7%2 = 1)
- ** (Exponentiation: 2**3 = 8)
Relational & Logical
- == (Equal to), != (Not equal)
- > (Greater than), < (Less than)
- >= (Greater or equal), <= (Less or equal)
- and (True if both conditions True)
- or (True if at least one True)
- not (Inverts boolean truth value)
3. Flow of Control (Conditions & Loops)
Conditionals (if-elif-else)
Evaluates logical conditions. Indentation (4 spaces) is required to group code blocks.
Loops (for & while)
for iterates through sequences like range(1, 11); while iterates as long as a condition remains True.
4. Python Lists
Lists are ordered, mutable sequences enclosed in brackets. Elements support both positive indexing (0 to length - 1) and negative indexing (-1 from right). Slices follow list[start : stop] where stop is exclusive. Common methods include append(), extend(), insert(), remove(), pop(), and sort().