Skip to content
Portfolio

Python Core Concepts

var1 = "hello"
item = "Code 101"
print(type(item))
# Example of a single-line comment

When comparing floats directly, we may run into precision issues:

0.1 * 3 == 0.3 # False

To tackle this, we can use the math.isclose() function:

import math
math.isclose(0.1 * 3, 0.3) # True
  • +, -, *, /
  • / true division -> float
  • // floor division -> integer or float
  • % modulo -> remainder
  • ** -> power
  • Concatenation (+): Joins strings.
  • Length (len()): Gets the number of characters.
  • Indexing ([]): Access a character by position (0-based).
  • Slicing ([:]): Extract substrings.
  • .lower() / .upper(): Converts the entire string to uppercase or uppercase
  • .strip() / .lstrip() / .rstrip(): Removes invisible whitespace and newline characters (\n) from the edges.
  • .startswith() / .endswith(): Returns a Boolean (True or False) if the string starts/ends with a specific pattern.
  • .split() : Breaks a string apart into a List, splitting it at a character you define.
  • .join(): The exact reverse of split. Takes a List and glues it together into a single string.
  • .replace(): Swaps a specific substring with another one.