← Tools / 🐍 Python Playground
Take the Python course →
🐍

Python Playground

Write and run Python 3 in your browser — no installation needed. Uses the Piston API to execute code securely on a remote server.

Python
⌨️

Keyboard shortcut

Press Tab inside the editor to insert 4 spaces.

📥

Using input()

Click ▼ stdin (or "Need input?") and type your inputs — one per line, matching each input() call.

📦

Standard library

Most built-in modules are available: math, random, string, collections, datetime, and more.

Quick-start snippets

Input & output

name = input("Name: ")
print(f"Hello, {name}!")

for loop

for i in range(1, 11):
    print(i)

while loop

n = 1
while n <= 10:
    print(n)
    n += 1

if / elif / else

x = int(input("Number: "))
if x > 0:
    print("Positive")
elif x < 0:
    print("Negative")
else:
    print("Zero")

List & for each

scores = [72, 85, 91, 60]
total = sum(scores)
print(f"Average: {total/len(scores):.1f}")

Function

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))