What is Python?
Python is a computer language that helps us talk to computers and tell them what to do.
It’s like giving step-by-step instructions — but in words that are easy to read and write.
Python is used for many cool things:
Building games 🎮
Making apps and websites 💻
Doing science and math 🧮
Working with robots 🤖
Tools for Python
To write Python code, we need a code editor or IDE.
Think of it like a notebook where you write your Python stories.
There are many tools you can use:
VS Code (Visual Studio Code) — light, easy, and great for beginners
PyCharm — very powerful for big projects
Thonny — made for students learning Python
IDLE — comes with Python automatically
💡 Using VS Code for Python
Since you’re using VS Code, here’s what to do:
1. Open VS Code
2. Install Python Extension by Microsoft (very important!)
3. Install Code Runner (to run code easily)
4. Install Pylance (to get smart suggestions)
✅ Best Python Extensions for VS Code
Python (by Microsoft) → runs your code
Pylance → gives hints and checks errors
Code Runner → lets you run code fast
Python Built-in Functions
Python comes with many ready-made tools called built-in functions.
They help us do things faster without writing long code.
Think of them like shortcuts for your brain — Python already knows what to do! 😎
💬 1. print()
Shows messages or results on the screen.
print("Welcome to Python!")
🖥️Output:
Welcome to Python!
💬 2. input()
Takes information from the user.
name = input("What is your name? ")
print("Hello", name)
What is a Variable?
A variable is like a box where we can store information.
It keeps things like names, numbers, or messages so we can use them later.
Think of it like a labeled container — you give it a name and put something inside.
💬 Example:
name = "Femi"
age = 12
🧩 Here:
The word name is the box label.
The value "Femi" is what’s inside the box.
Same with age = 12, the number 12 is stored inside age.
💡 What Can We Store in a Variable?
We can store different types of data, such as:
Type Example What It Means
Text (string) "Hello" Words or sentences
Number (integer) 10 Whole numbers
Decimal (float) 3.5 Numbers with a point
True/False (boolean) True or False Yes or No values
List [1, 2, 3] Many values in one box
💬 Example:
name = "Ada"
age = 10
height = 1.45
is_student = True
subjects = ["Math", "English", "Science"]
🧠 Why Use Variables?
Because they help us reuse data easily without writing it many times.
Example:
name = "John"
print("Hello", name)
print(name, "is learning Python!")
🖥️Output:
Hello John
John is learning Python!
⚙️Variable Names — DOs and DON’Ts
When naming your variable, there are some rules you must follow 👇
✅ DOs
1. Use only letters, numbers, and underscores _.
2. first_name = "Tola"
3. age1 = 11
4. The name must start with a letter or underscore, not a number.
✅ name1 is good
❌ 1name is wrong
5. Use clear names so your code makes sense.
✅ score = 95
❌ x = 95 (too confusing)
6. Python is case-sensitive (it sees Age and age as different).
7. Age = 12
8. age = 13
9. print(Age) # 12
10. print(age) # 13
❌ DON’Ts
1. Don’t use spaces — use underscores _ instead.
❌ first name = "Ada"
✅ first_name = "Ada"
2. Don’t use Python keywords (like print, if, for, etc.) as names.
❌ if = 10 (❌ this breaks your code)
✅ my_if = 10
3. Don’t use special characters like @, #, $, -, or !.
❌ user-name = "Bola"
✅ user_name = "Bola"
What is a String?
A string is text — words, letters, sentences, anything inside quotes.
Examples:
"Hello"
'Hi'
"123" # this is text, not a number
You make strings with single or double quotes. They’re the same.
✨ What can we do with strings?
We can:
Count letters
Change case (upper/lower)
Cut parts out (slicing)
Join words
Find words
Replace parts
Check letters/numbers
Format messages with values
🔢 Built-in function: len()
len() tells how many characters are in a string (including spaces).
Example:
name = "Femi"
print(len(name)) # 4
sentence = "Hi there!"
print(len(sentence)) # 9 (space and exclamation count)
🔪 Slicing strings (cutting parts)
Use string[start:end] to get a piece.
start = where to begin (0 = first character)
end = where to stop but not include (like LEGO stop point)
Examples:
word = "Python"
print(word[0:2]) # 'Py' (starts at 0, stops before 2)
print(word[2:]) # 'thon' (from index 2 to end)
print(word[:3]) # 'Pyt' (from start to position 3-1)
print(word[-1]) # 'n' (last character)
print(word[-3:]) # 'hon' (last 3 characters)
You can also use a step: string[start:end:step]
s = "abcdef"
print(s[0:6:2]) # 'ace' (take every 2nd char)
🔥 Escape sequences (special characters inside strings)
Use \ to put special things in strings.
Common ones:
\n → new line
\t → tab (space)
\\ → put a backslash \
\" → put a double quote inside double quotes
\' → put a single quote inside single quotes
Examples:
print("Hello\nWorld")
# prints:
# Hello
# World
print("She said: \"Hi!\"")
# prints: She said: "Hi!"
🧾 Formatted strings (f-strings) — best for building
messages
Put f before the string and use {} to insert variables.
Example:
name = "Tola"
age = 11
print(f"Hello {name}, you are {age} years old!")
# Hello Tola, you are 11 years old!
You can do math inside too:
a = 5
b = 3
print(f"{a} + {b} = {a + b}") # 5 + 3 = 8
🛠 Common string methods (functions that belong to
strings)
I’ll show each with what it does + an example.
upper() / lower()
Make all letters big or small.
s = "Hello"
print([Link]()) # "HELLO"
print([Link]()) # "hello"
title() / capitalize()
title() => first letter of each word big. capitalize() => first letter of whole string big.
s = "hello world"
print([Link]()) # "Hello World"
print([Link]()) # "Hello world"
strip() / lstrip() / rstrip()
Remove spaces from sides.
s = " hi "
print([Link]()) # "hi"
print([Link]()) # "hi " (left removed)
print([Link]()) # " hi" (right removed)
replace(old, new)
Change part of the string.
s = "I like cats"
print([Link]("cats", "dogs")) # "I like dogs"
find(sub) / index(sub)
Find where a substring starts. find returns -1 if not found; index gives an error if not found.
s = "banana"
print([Link]("na")) # 2 (first 'na' starts at index 2)
print([Link]("xy")) # -1
# [Link]("xy") would cause an error
split(separator)
Split string into a list by separator (default is space).
s = "apple banana cherry"
print([Link]()) # ["apple", "banana", "cherry"]
print("a,b,c".split(",")) # ["a", "b", "c"]
join(iterable)
Opposite of split — join a list into a string.
words = ["I", "love", "Python"]
print(" ".join(words)) # "I love Python"
startswith(prefix) / endswith(suffix)
Check how string begins/ends — returns True/False.
s = "[Link]"
print([Link]("Hell")) # True
print([Link](".py")) # True
isdigit() / isalpha() / isalnum()
Check if all characters are digits, letters, or letters+numbers.
print("123".isdigit()) # True
print("abc".isalpha()) # True
print("a1".isalnum()) # True
count(sub)
How many times a substring appears.
s = "banana"
print([Link]("a")) # 3
✅ Quick examples combining many things
text = " Hello Python! "
print(len(text)) # length includes spaces
clean = [Link]()
print(clean) # "Hello Python!"
print([Link]()) # "HELLO PYTHON!"
print(clean[6:12]) # "Python" (slicing)
words = [Link]() # ["Hello", "Python!"]
print(words[1].replace("!", "")) # "Python"
print(f"The second word is {words[1].replace('!', '')}")
Output step-by-step:
len(text) maybe 16
clean → "Hello Python!"
[Link]() → "HELLO PYTHON!"
clean[6:12] → "Python"
words → ["Hello", "Python!"]
final print → The second word is Python