Mathew K Analytics

Lesson 7 · Python for Data Science

Python and Jupyter Notebooks for Beginners: A Step-by-Step Guide

In this video, we will explore Python basics using Jupyter. Jupyter notebooks help you write and run code step by step. Python is a popular language for…

⬇ Download notebookOpen in Colab ↗

What you'll learn

Data

No separate download needed — the notebook creates or downloads everything it uses.

📓 Full notebook

Download .ipynb
 

Welcome to Your First Python Jupyter Notebook Lesson!#

In this video, we will explore Python basics using Jupyter.

Jupyter notebooks help you write and run code step by step.

Python is a popular language for beginners because it is easy to read and use.

Let us get started and see what Python can do!

What is a Jupyter notebook?#

Jupyter notebooks let you mix code, explanations, and results.

You can run code in small pieces, called cells.

This makes it easy to learn, try things, and fix mistakes.

# Let us print a friendly message
print('Hello, world!')
Hello, world!
# Variables store data so you can use it later
name = 'Alice'
print(name)
Alice
# Use input() to ask the user a question
user_food = input('What is your favorite food? ')
print('Yum! I like', user_food, 'too.')
Yum! I like pizza too.
 
# Math is easy in Python
a = 5
b = 3
sum_ab = a + b
print('5 plus 3 is', sum_ab)
5 plus 3 is 8

Practice: Print your name and age#

Try using print() to show your name and age in a message.

# Python can do more than just print text.
# It can store different types of data.

age = 21
height = 1.75
is_student = True
print('Age:', age)
print('Height (meters):', height)
print('Student status:', is_student)
Age: 21
Height (meters): 1.75
Student status: True
# You can put several things together in a list.
colors = ['red', 'green', 'blue']
print('Favorite colors:', colors)
Favorite colors: ['red', 'green', 'blue']
# Access items in a list using square brackets.
print('First color:', colors[0])
print('Second color:', colors[1])
First color: red
Second color: green
# Use input to build your own list
animal_1 = input('Name an animal: ')
animal_2 = input('Name another animal: ')
animals = [animal_1, animal_2]
print('Your animals:', animals)
Your animals: ['dog', 'cat']
 
# Lists can be changed after you create them.
colors.append('yellow')
print('New colors list:', colors)
New colors list: ['red', 'green', 'blue', 'yellow']
# Remove an item from a list
colors.remove('green')
print('Colors after removing green:', colors)
Colors after removing green: ['red', 'blue', 'yellow']
# Sometimes things go wrong. Let us handle errors.
try:
    colors.remove('purple')
except ValueError:
    print('Could not find purple!')
    
Could not find purple!

Useful List Methods#

  • .append(): Add an item
  • .remove(): Delete an item by value
  • .pop(): Take out an item by place
  • .sort(): Put items in order

Try using these on your own list!

# You can repeat actions with loops.
for color in colors:
    print('Color:', color)
    
Color: red
Color: blue
Color: yellow
# List comprehensions are a quick way to create new lists.
squared = [x * x for x in range(5)]
print('Squares:', squared)
Squares: [0, 1, 4, 9, 16]
# Sort a list in alphabetical order.
colors.sort()
print('Sorted colors:', colors)
Sorted colors: ['blue', 'red', 'yellow']
# Combine two lists together.
combined = colors + animals
print('All items:', combined)
All items: ['blue', 'red', 'yellow', 'dog', 'cat']
# Real-world data: make a shopping list
shopping = []
for i in range(3):
    item = input(f'Enter item {i+1}: ')
    shopping.append(item)
print('Your shopping list:', shopping)
Your shopping list: ['milk', 'bread', 'eggs']
 
# Mini-Project: Find the longest word in your shopping list
longest = ''
for word in shopping:
    if len(word) > len(longest):
        longest = word
print('The longest word on your list is:', longest)
The longest word on your list is: bread
# Best practice: check before removing items
if 'milk' in shopping:
    shopping.remove('milk')
else:
    print('Milk was not found in the shopping list.')
print('Shopping list now:', shopping)
Shopping list now: ['bread', 'eggs']
# Common mistake: spelling errors
# watch for spelling differences in item names
if 'bread' in shopping:
    print('Bread found!')
else:
    print('Bread is missing. Check your spelling!')
    
Bread found!
# Tips: Make a backup of your list using copy()
backup = shopping.copy()
shopping.clear()
print('Backup:', backup)
print('Cleared shopping:', shopping)
Backup: ['bread', 'eggs']
Cleared shopping: []
# Challenge: practice with your own list
my_list = []
for i in range(2):
    word = input('Add anything: ')
    my_list.append(word)
print('Your list:', my_list)
Your list: ['car', 'phone']
 

Recap: You did it!#

You learned how to:

  • Print messages
  • Store data in variables and lists
  • Use input() and loops
  • Modify, sort, and combine lists
  • Practice safe coding

Keep experimenting and practicing.

Every new notebook is a chance to learn and grow!

Thank you for learning Python in Jupyter Notebooks!#

If you found this lesson helpful, please like the video, leave a comment, and subscribe for more beginner Python tutorials!

Share your notebook with a friend and help them start learning too.

Happy coding!

Found this useful?

All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.