1. Home
  2. /
  3. Pyscript
  4. /
  5. Variables Example

Variables Example - Pyscript Typing CST Test

Loading…

Variables Example — Pyscript Code

Defines variables in PyScript and prints them.

<!DOCTYPE html>
<html>
<head>
	<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
	<py-script>
		x = 42
		name = 'Alice'
		print(x, name)
	</py-script>
</body>
</html>

Pyscript Language Guide

PyScript is a framework that allows running Python code directly in web browsers using HTML and JavaScript integration. It bridges Python with the web platform, enabling interactive applications without traditional backend setup.

Primary Use Cases

  • ▸Embedding Python code in web pages for interactivity
  • ▸Educational platforms teaching Python in the browser
  • ▸Interactive data visualizations with Python libraries
  • ▸Prototyping web apps quickly using Python
  • ▸Combining Python and JavaScript for hybrid applications

Notable Features

  • ▸Write Python directly in HTML with `<py-script>` tags
  • ▸Access JavaScript objects and browser APIs from Python
  • ▸Support for popular Python libraries like NumPy, Pandas, and Matplotlib
  • ▸Live code execution in browser without server
  • ▸Integration with Pyodide for WebAssembly-based Python runtime

Origin & Creator

Created by Anaconda, Inc., first announced in 2022, inspired by the desire to make Python a first-class citizen for web development alongside JavaScript.

Industrial Note

Used in education, prototyping, and interactive demos; suitable for web-based Python experimentation but not yet a replacement for full-scale web frameworks.

More Pyscript Typing Exercises

Hello World in PyScriptPyScript If Statement ExamplePyScript Loop ExamplePyScript Function ExamplePyScript Input ExamplePyScript Math ExamplePyScript List ExamplePyScript Conditional Loop ExamplePyScript Simple Plot Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher