Syntax

Python Slice a List Syntax

In Python, slice a list: gets part of a list or string — items[1:4]

Quick Answer

Syntax
items[1:4]
PythonSyntax

Slice a List

Code example
items[1:4]

Gets part of a list or string.

Learn More

How to slice a list in Python

  1. Open your Python file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Python Slice a List Syntax

Use items[1:4].

Related Syntax References

Frequently asked questions

What is the Python syntax for slice a list?

Use this pattern: items[1:4]

Can I copy this Python code example?

Yes. Use Copy code and adapt the example to your program.

Is this Python syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify