Float

2 snippets across 2 stacks — HTML & CSS, Python

HCHTML & CSS

Float & Clear

HC · Layout & Positioning
syntax
float: left | right | none;
clear: left | right | both;
example
/* Classic text wrapping around an image */
.article-image {
  float: left;
  margin: 0 16px 16px 0;
  max-width: 40%;
}

/* Clear floats */
.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

Note Floats were once used for page layouts but flexbox and grid have replaced that use case. Floats are still useful for wrapping text around images. Use the clearfix hack or display: flow-root on the parent to contain floated children.

PYPython

Integers & Floats

PY · Numbers
syntax
x = 42      # int
y = 3.14    # float
example
count = 1_000_000
ratio = 0.618
print(type(count), type(ratio))
print(count + ratio)
output
<class 'int'> <class 'float'>
1000000.618

Note Underscores in numeric literals are ignored and serve as visual separators. Python ints have unlimited precision.