Guide to High School Computer Science
  • 💻Introduction
    • windows & Python Development
    • macOS & Python Development
    • Visual Studio Code Settings
    • Set up Github
    • Author Page
  • 🧠Prerequisite Skills
    • Keyboard Typing
    • Files & Directories
    • Use of Command Line
    • Git & GitHub
    • Markdown
    • Starting Your Python Project
  • 🐍Python Programming
    • 🍎Python Basics
      • What is Python?
      • Procedural Programming & Programming Paradigms
      • String Formatting
      • Data Types
      • Input & Output to Console
      • Working with Numbers
      • Useful Built-in Functions
      • Math & Random Module
      • Boolean Data Object
      • Comparison, Logical, and Membership Operators
      • If Statements
      • Binary Decisions
      • Multiple Decisions
      • Nested Conditions
      • [EXTRA] Bitwise Operators
      • [EXTRA] Python Style Guide
    • ⏮️Iterations
      • Introduction to While Loops
      • Infinite Loop
      • Controlling Your While Loops
      • Introduction to For Loops
      • For Loops w/ Numeric Sequences
      • For Loops w/ Strings & Lists
      • Iterable Functions w/ For Loops
    • 📦Collections
      • Strings
        • String Basics
        • String Indexing
        • String Slicing
        • String Operators & Functions
        • Basic String Methods
        • String Methods Extended
        • String Methods Document
      • Tuples & Lists
        • Tuples
        • List Basics
        • List are Mutable
        • Adding Items to a List
        • Removing Items from a List
        • Search & Reverse a List
        • List Comprehension
        • List Methods Document
      • Sets
      • Dictionary
      • How to Store Multiple Data Items
    • 💡Defining Functions
      • Functions
      • print() vs return
      • Pre-determined Arguments
      • Nested Functions
      • Map & Filter
      • [Extra] Dynamic Arguments
    • 💾File I/O
      • How to Save Text to an External File
      • Reading CSV in Python
      • Reading JSON in Python
    • 🔨Basic Python Projects
      • Basic Calculator
        • Improving the calculator
        • Exercise Set 1
        • Exercise Set 2
        • 💎Streamlit Application #1
      • Basic Password Generator
        • Exercise Set 3
        • Exercises Related to Math
        • 💎Streamlit Application #2
      • A To-Do Task List
    • ⏳Introduction to Algorithmic Thinking
      • Big-O Notation
      • Basic Algorithms
        • Linear Search
        • Binary Search
        • Basic Sorting Algorithms
      • Recursion
      • Brute Force Algorithms
      • Greedy Algorithm
        • Time on Task (CCC 2013 J4)
        • Dijkstra’s Algorithm
      • Divide and Conquer
        • Merge Sort
      • Dynamic Programming
    • 🤯Object Oriented Programming
      • Class & Objects (Definitions)
      • OOP in Python
      • Encapsulation
      • Polymorphism
      • Inheritance & Overriding
      • Override Magic Methods
      • Case Study: 2D Vectors
      • Case Study: Deck of Cards
      • Exercise
      • Abstract Data Types
      • Case Study: Static 1D Array From Java
    • Competitive Programming
      • Is This Sum Possible?
        • Is the dataset sorted?
        • Searching for a value
        • Determine if the difference between an integer from the array and the target value exists
        • Sorting Algorithms
        • Using Two Pointers
      • Two Sum - LeetCode
        • Generate all possible pairs of values
        • Subtract each value from the target, see if the difference exists in the list
      • Longest Common Prefix - LeetCode
        • Compare all possible prefixes
        • Create the longest common prefix with the direct neighbour
      • Length of Last Word - LeetCode
        • Compare all possible prefixes
      • Where can I go from one point to another?
      • Sample Outline
    • IB Recipe Book
  • 💾Python & Databases
    • Intro to Databases & Data Modeling
      • Common Data Types in SQL
      • Introduction to ERDs
      • Primary Keys and Foreign Keys
      • Database Normalization
    • What is SQL?
      • Getting Started
      • SELECT Queries
        • Selection with Conditions
        • Selection with Fuzziness
        • Selection and Sorting in Order
        • Selection without Duplicates
        • Selection with Limited Number of Outputs
      • AGGREGATE Queries
        • Counting Rows
        • Sum, Average, Min/Max Queries
        • Working with Aggregate Queries
        • Power of using Groups
        • Exercise
      • Interacting with Multiple Table
      • Inserting Data
      • External Resource
  • ☕Java Essentials
    • Basics
      • Starting Java
      • Data & Variables
      • Handling User Inputs & Type Conversion
      • Arithmetic
      • IPO Model
      • Basic Built-in Methods
      • Exercise Questions
    • Conditionals
      • Boolean Operators
      • Compare Strings
      • If Statements
      • If Else Statements
      • Making Multiple Decisions
      • Using Switch
      • Flowchart Symbols
      • Exercise Questions
    • Iterations
      • While Loops
      • For Loop
      • Exercises
    • Java Type Casting
    • Strings
      • Common String Practices
      • String Formatting
      • Java Special Characters
    • Collection
      • Arrays
      • For Each Loop
      • ArrayList
      • Exercise Questions
    • Static Methods
      • (Aside) Clearing your Console
    • Randomness in Java
    • Delayed Output in Java
    • Java Output Formatting
    • Java Style Guide
  • 🛠️JavaScript Programming
    • Our Programming Editor & Workflow
      • Hello, world!
      • Commenting & Variables
      • Data in JavaScript
      • Operators
      • String Formatting
      • Getting User Input
    • JavaScript Exercise Set 1
    • Making Decisions
      • Comparing Values
      • Combining Boolean Comparisons
      • Creating Branches
    • JavaScript Exercise Set 2
    • While Loops
      • Infinite While Loop
      • While Loops and Numbers
      • While Loops and Flags
      • While loops w/ Strings
    • JavaScript Exercise Set 3
    • Subprograms & Functions
      • Creating a Function in JavaScript
      • Function with Input and Assignable Output
    • JavaScript Exercise Set 4
  • 💾Topics in CS
    • Computer Environments & Systems
      • Computer Components
        • In-depth Explanations
      • File Maintenance
      • Computer & Safety
      • Software Development
      • Bits & Binary
    • Careers related to Computer Science
    • Postsecondary Opportunities
Powered by GitBook
On this page
  • Python & Data
  • Immutability & Mutability
  • Immutable Data Objects
  • Mutable Data Objects
  • Type Casting
  1. Python Programming
  2. Python Basics

Data Types

PreviousString FormattingNextInput & Output to Console

Last updated 3 months ago

Python & Data

In Python, all built-in data that can be used are all considered as objects. The concept of objects will be covered in . Due to such concept, we must understand the concept of mutability.

Immutability & Mutability

A data object in Python is can be considered either immutable or mutable.

  • An immutable data cannot be modified without recreating the data through an assignment operation

  • A mutable data can be modified without recreating the data. (It can have its inner content changed without an assignment operation)

Immutable Data Objects

# numeric data
number = 42 # an integer based variable
decimal = 3.14159 # a floating point number based variable

Integer objects are whole numbers that range from negative infinity to positive infinity. Python will have limitations of the computer system itself.

Floating Point objects are decimals of Python; moreover, floating points represent all the real numbers.

Since classical computers use a binary-number system, it does struggle with decimals. There is a great video that you can watch .

# text-based data
birthday = "January 1st 2000"

user_name = 'Jane Doe'

lorem_ipsum = """
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
"""

Strings are a powerful object that will come with built-in for manipulation and comparison which will be studied later.

Any long-text that you want to preserve formatting we often use triple quotation marks.

Some characters will be illegal (example: "Jane "The Programmer" Doe") will not be a valid string as there are too many quotation marks in a single line.

The fix:

name = "Jane \"The Programmer\" Doe"

# Decisional Data: boolean

is_late = False
loop = True

Boolean objects represents the concept of logical truth. It can have two possible values: True and False.

Booleans are fundamental in decision-making and controlling the flow of programs.

# Collection Data 1: Tuple

user = ("Jane Doe", "January 1st 2000", 1)

Mutable Data Objects

Lists, Sets, and Dictionaries are all similar to strings in that they have their respective methods. These are important data objects; therefore, they will be highlighted in their own pages.

# Collection Data 2: List

nums = [3,1,4,1,5,9]
words = ["Hello", "World"]
user = ["Jane Doe", "January 1st, 2000", 1]
# Collection Data 3: Sets

fruits = {"Apple", "Banana", "Strawberry"}
nums = {3,1,4,1,5,9}
 # Collection Data 4: Dictionary
 
 user = {
     "id" : 1,
     "name" : "Jane Doe",
     "birthday" : "January 1st, 2000"
 }

Type Casting

Type casting, also known as type conversion, is the process of converting an object from one data type to another in Python. It allows you to change the interpretation and representation of data. Python provides several built-in functions for type casting, which allow you to convert variables from one type to another.

The following are the type casting function to convert one data to another

  • int() | will convert to integers if possible, will round down always

  • float() | will convert to decimals if possible, whole numbers will be given .0

  • str() | will convert any data to string

  • bool() | will convert any data to a Boolean

  • tuple() | will convert any sequence like data to a tuple

  • list() | will convert any sequence like data to a list

  • set() | will convert any sequence like data to a set, duplicates will be removed, order may be different

  • dict() | will convert any sequence with a some sort of key value pairing to a dictionary

objects represent any textual data in Python. To create string data, you must trap the text in either single ('') or double quotation marks ("").

can be used to help meditate any issues on adding such illegal characters to strings properly.

is one of many data objects that allows multiple items to be stored in a single variable container.

objects are a mutable container of any data where we can dynamically add new items, extend it with another list, and remove values from it.

objects are based on . Sets can only contain a single copy of an item (no duplicates allowed), and the items that are immutable. Sets are often used for their membership operators as it is much faster than other data types.

objects are ways to create a collection of key (address) to value pairs. Dictionaries allow you to have a unique address for each of your items for fast retrieval.

🐍
🍎
a future chapter
here
String
Escape Character
Tuple
List
Set
mathematical definition of sets
Dictionaries