1 of 22

BinaryTree

Intermediate

Python Course

BinaryTree Digital Education Program

2 of 22

Week 1

Python Fundamentals Review

& Best Practices

3 of 22

Basic Data Types and Structures in Python

In programming, data types tell Python what kind of information is stored in a variable. Just like filling out a form — your name (text), age (a number), whether you're a student (yes/no) — Python needs to know the type of data it's dealing with.

Character

String

Integer

Float

Double

Boolean

4 of 22

Basic Data Types — String (str)

String (str)

→ Used for text

A sequence of characters enclosed in quotes (" " or ' ').

• Used in messages, user input, and filenames

• Multiline: use triple quotes (""" or ''')

• Concatenate with the + operator

Examples:

"Hello, world!"

'Python is fun!'

5 of 22

Basic Data Types — Integer (int)

Integer (int)

→ Whole numbers

A whole number — no decimal points.

• Used for counting, indexing, and math

• Large integers can use underscores for readability

Examples:

42, -7, 1000

1_000_000 (same as 1000000)

6 of 22

Quick Check: Which can be initialized as an int?

6.09

4.0

3E10

10^5

1.0009

5*4.0

8a

19865339

Think about what makes a number an integer — discuss with your partner!

7 of 22

Basic Data Types — Float & Double

Float

→ 32-bit decimal (≈7 decimal places)

A number with decimal points.

Used in scientific calculations, percentages, and measurements.

Examples: 3.14, -0.5, 2.0

⚠ Important: Python uses the keyword float but internally saves with double precision!

Double

→ 64-bit decimal (≈15 decimal places)

More precision than a float.

Wider usage due to higher accuracy, but takes more memory.

Examples: 3.14, -0.5, 2.0

In Python, float and double are the same — Python defaults to double precision.

8 of 22

Double vs. Float — Discussion

1

Which has higher precision?

2

Which takes up more memory?

3

Does Python have doubles and floats? Explain.

4

Does Java have doubles and floats? Explain.

9 of 22

Basic Data Types — Character (char)

Character (char)

→ A single character

Holds exactly one character.

Strings are essentially a series of characters.

⚠ In Java/C++, characters use single quotes.

In Python, a single-char string serves the same purpose.

Examples: "c", "$", "@"

10 of 22

Basic Data Structures — Lists

List → A collection of items that can change�

• Holds any data type, including strings�

• Each item has an index starting at 0�

• You can add, remove, and modify elements�

• Use .index() to find the position of a value

sports_cars = ["Ferrari", "Lamborghini", "Koenigsegg", "Pagani", "Bugatti"]�lambo_index = sports_cars.index("Lamborghini") # → 1

11 of 22

Basic Data Structures — Dictionaries

Dictionary → A collection of key-value pairs

• Stores data as key: value pairs — keys must be unique�

• Great alternative to lists when you need labelled lookup�

• Lookup is O(1) vs O(n) for lists — much faster at scale

player = {"name": "Alex", "level": 10, "active": True}�player["level"] # → 10�player["score"] = 250 # add a new key

12 of 22

Takeaways: Lists vs. Dictionaries

Feature

List

Dictionary

Key-based lookup

✗ (index only)

✓ (unique keys)

Lookup time

O(n)

O(1)

Mutable

Maintains insertion order

✓ (Python 3.7+)

✓ (Python 3.7+)

13 of 22

Time Complexity — Big O Notation

Big O notation describes how an algorithm's runtime grows as input size increases. It tracks two key variables: memory and speed.

O(1)

Constant Time

Runtime does not change with input size.

Example: Accessing arr[0] or dict[key]

O(log n)

Logarithmic Time

Runtime increases slowly as input grows.

Example: Binary search

O(n)

Linear Time

Runtime grows proportionally to input size.

Example: Looping through an array

14 of 22

Basic Data Types — Boolean (bool)

Boolean (bool)

→ True or False

A statement that returns either True or False.

Stored in binary: 0 = False, 1 = True.

Used when:

• Code execution depends on a condition

• You need if/else decision-making

• Validating user input

Examples: True, False

if is_logged_in: ...

15 of 22

Example Code — All Data Types

This code implements all the data types covered today. What do you think it outputs?

name = "Alice"age = 17gpa = 3.85is_student = Truesubjects = ["Math", "CS", "Physics"]�info = {"school": "BinaryTree", "grade": 11}��print(f"Name: {name}, Age: {age}, GPA: {gpa}")

16 of 22

Practice Question

Which data type is most appropriate for tracking whether a user is currently logged in, and why?

A

String

B

Integer

C

Boolean

D

Object

17 of 22

Practice Question

In an online store class, which variable would most likely be a float?

A

stock_quantity

B

product_name

C

product_price

D

is_discounted

18 of 22

Practice Question

Which variable type would be least appropriate for storing a list of newsletter subscribers?

A

Set

B

List

C

Tuple

D

Dictionary

19 of 22

Functions

Encapsulating reusable logic in Python

20 of 22

Practice Question

Which statement is true about variable types in the provided code?

A

final_price is a String because it is formatted for printing.

B

item_discount should be an Integer — discounts are whole numbers.

C

subtotal is a Float because it represents total price before discount.

D

item_name is a Float because it represents the name of an item.

Instructor-led — walk through the code together before revealing the answer.

21 of 22

Practice Question

Which of the following are correct statements about variable types and functions in Python? (Select all that apply)

A

A function can return any type, including complex structures like lists and dicts.

B

A Boolean can only store True or False and is used in conditional expressions.

C

str is best suited for representing numerical values in math calculations.

D

A function can modify an argument if it is passed by reference.

E

int can store floats — it rounds to the nearest integer.

F

list is mutable — its elements can be changed after creation.

22 of 22

Week 1 Wrap-Up

Last Thoughts

1

Review the practice questions in these slides.

2

Reach out if you have any further questions.

3

Look out for mid-week practice resources on more complex applications of today's topics.

Thank you!