FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

25 snippets foundClear filters
PythonGetting Started

Name a value that stays fixed

Python: Use a constant declaration or the language’s constant naming convention for a fixed limit.

Python✓ Tested
PythonGetting Started

Print a number with two decimal places

Python: Format a small decimal value consistently for display.

Python✓ Tested
PythonGetting Started

Read one character from ASCII text

Python: Use a valid zero-based index to read the first character.

Python✓ Tested
PythonGetting Started

Read the beginning of a text value

Python: Extract or display the first three ASCII characters from a known nonempty string.

Python✓ Tested
PythonGetting Started

Read the first collection element

Python: Access index zero only after establishing that the collection is nonempty.

Python✓ Tested
PythonGetting Started

Repeat a fixed number of times

Python: Use a counted loop to print three numbered steps.

Python✓ Tested
PythonGetting Started

Repeat while a condition holds

Python: Count down while a positive number remains, updating the loop variable on each iteration.

Python✓ Tested
PythonGetting Started

Replace one collection element

Python: Update an existing element at a known valid index.

Python✓ Tested
PythonGetting Started

Require two conditions to be true

Python: Combine a lower and an upper bound to check whether a value is in range.

Python✓ Tested
PythonGetting Started

Run your first program

Python: Start with a complete program that prints one line. Follow the run instructions below.

Python✓ Tested
PythonGetting Started

Store a value in a named variable

Python: Give a value a descriptive name and print it.

Python✓ Tested
PythonGetting Started

Update a running count

Python: Change a variable after its initial value has been assigned.

Python✓ Tested