Python Programming Fundamentals
A Comprehensive Introduction
POWERED BY LIA
Introduction to Python
Readability: Clean syntax with emphasis on code readability
Versatility: Used in web development, data science, AI,
automation, and more
Extensive Libraries: Rich ecosystem of libraries and
frameworks
Community: Large, active community providing support and
resources
Brief History
Created by Guido van Rossum and first released in 1991. Named after the
British comedy group Monty Python. Python 3, the current major version,
was released in 2008.
POWERED BY LIA
Variables
Variables are containers for storing data values. In Python, a variable is
created when you assign a value to it.
age = 25 # Integer
name = "John" # String
height = 5.9 # Float
is_student = True # Boolean
scores = [95, 87, 92] # List
Variable Naming Rules:
Must start with a letter or underscore
Can contain letters, numbers, and underscores
Case-sensitive (age, Age, and AGE are different variables)
Cannot start with a number
Cannot use reserved keywords (if, for, while, etc.)
POWERED BY LIA
Strings
Strings are sequences of characters enclosed in quotes. Python
supports both single and double quotes for string creation.
message = "Hello, Python!"
name = 'John'
multi_line = """This is a
multi-line string"""
# String operations
greeting = "Hello" + " " + "World" # Concatenation
repeated = "Python! " * 3 # Repetition
first_char = greeting[0] # Indexing
substring = greeting[0:5] # Slicing
Common String Methods:
Method Description Example
upper() Converts to uppercase "hello".upper() → "HELLO"
lower() Converts to lowercase "HELLO".lower() → "hello"
strip() Removes whitespace " hello ".strip() → "hello"
replace() Replaces occurrences "hello".replace("l", "x") → "hexxo"
POWERED BY LIA
split() Splits into a list "a,b,c".split(",") → ["a", "b", "c"]
Arithmetic Operations
Operator Name Example Result
+ Addition 5+3 8
- Subtraction 5-3 2
* Multiplication 5*3 15
/ Division 5/3 1.6666...
// Floor Division 5 // 3 1
% Modulus 5%3 2
** Exponentiation 5 ** 3 125
x = 10
y = 3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333...
print(x // y) # 3
print(x % y) # 1 POWERED BY LIA
Comparison Operations
Operator Name Example Result
== Equal to x == y True if x equals y
!= Not equal to x != y True if x is not equal to y
> Greater than x>y True if x is greater than y
< Less than x<y True if x is less than y
Greater than or equal True if x is greater than or
>= x >= y
to equal to y
True if x is less than or equal to
<= Less than or equal to x <= y
y
x = 10
y = 5
print(x == y) # False
print(x != y) # True
print(x > y) # True
print(x < y) # False
print(x >= y) # True
print(x <= y) # False POWERED BY LIA
Identity Operations
Identity operators are used to compare the memory locations of two
objects to determine if they are the same object.
Operator Description Example
Returns True if both variables reference the same
is x is y
object
Returns True if both variables reference different
is not x is not y
objects
# Lists with same values but different objects
list1 = [1, 2, 3]
list2 = [1, 2, 3]
print(list1 == list2) # True (same values)
print(list1 is list2) # False (different objects)
# Same object reference
list3 = list1
print(list1 is list3) # True (same object)
Important Note
The is operator checks if two variables point to the same object in memory, while ==
checks if the values are equal. For immutable objects like integers within a certain range,
POWERED BY LIA
Python may reuse the same object, which can lead to unexpected behavior.
Assignment Operations
Assignment operators are used to assign values to variables. They
combine an arithmetic operation with assignment.
Operator Example Equivalent to
= x=5 x=5
+= x += 5 x=x+5
-= x -= 5 x=x-5
*= x *= 5 x=x*5
/= x /= 5 x=x/5
%= x %= 5 x=x%5
**= x **= 5 x = x ** 5
//= x //= 5 x = x // 5
x = 10
x += 5 # x becomes 15
print(x) # 15
x -= 3 # x becomes 12
print(x) # 12
x *= 2 # x becomes 24
print(x) # 24 POWERED BY LIA
Membership Operations
Membership operators are used to test if a sequence is present in an
object (like a string, list, tuple, or dictionary).
Operator Description Example
Returns True if a sequence with the specified value is
in x in y
present in the object
Returns True if a sequence with the specified value is
not in x not in y
not present in the object
fruits = ["apple", "banana", "cherry"]
text = "Hello, Python!"
print("apple" in fruits) # True
print("orange" in fruits) # False
print("orange" not in fruits) # True
print("Python" in text) # True
print("Java" not in text) # True
Works with these data types:
Lists, Tuples, Strings, Sets, and Dictionaries (checks keys)
POWERED BY LIA
Lists
Lists are ordered, mutable collections that can store items of different
data types. They are defined using square brackets [].
# Creating lists
fruits = ["apple", "banana", "cherry"]
mixed = [1, "Hello", 3.14, True]
# Accessing elements
print(fruits[0]) # apple
print(fruits[-1]) # cherry (last item)
# Slicing
print(fruits[0:2]) # ['apple', 'banana']
Common List Methods:
Method Description Example
append() Adds an element to the end fruits.append("orange")
insert() Adds element at specified position fruits.insert(1, "mango")
remove() Removes the first matching item fruits.remove("banana")
pop() Removes item at specified index fruits.pop(1)
sort() Sorts the list fruits.sort()
POWERED BY LIA
reverse() Reverses the list fruits.reverse()
Conclusion
Key Concepts Covered:
Variables and data types form the foundation of Python programming
Strings provide powerful text manipulation capabilities
Various operators (arithmetic, comparison, identity, assignment,
membership) enable different operations
Lists offer flexible data storage and manipulation
Next Steps for Learning:
Explore control structures (if statements, loops)
Learn about functions and modules
Study more complex data structures (dictionaries, sets, tuples)
Practice with real-world projects
POWERED BY LIA