HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Python: Print and RepeatVariablesData Types & NumbersStringsListsConditions (if / elif / else)Loops (for / while)FunctionsOperatorsDictionariesTuples & SetsError Handling (try / except)Classes (Object-Oriented)File OperationsComments & IndentationBooleans (True / False)Lambda & map / filterModules (import)InheritanceVariable Scope
REFERENCE
📖 Overview
🖥️ Output & Input
🔢 Numbers & Math
✍️ String
📋 List
items []append()insert()remove() / pop()sort() / sorted()reverse()slicing [a:b]
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
📁 File & Error
🔄 Type & Conversion
Python›REFERENCE›List›slicing [a:b]

slicing [a:b]

Takes a piece of the list/string.

Syntax

items[start:end:step]

Description

You take a subset with square brackets. Start is included, end is excluded. A negative index counts from the end, and the step specifies skipping.

Returns

New items/text (slice).

Example

Loading editor…

Expected output

Hex
ary
[0, 2, 4]

When to use?

Taking the first N characters, cutting off the last part, selecting a piece of a list.

Common mistakes

  • ⚠️ The end index is not included: h[0:3] takes 0,1,2, but not 3.

Related commands

items []len()
← reverse()
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code