Syntax Comparison: Python Vs Dart

Python VS Dart

Basic Syntax

TitlePythonDart
entry pointtop-level statementsvoid main()
indentationsignificant (spaces)curly braces {}
statement endnewlinesemicolon optional (but usually added)
type systemdynamic (PEP 526 annotations optional)static + inference + null-safety
constantsconvention: UPPER_CASEfinal (run-time once) or const (compile-time)

Basic Code in Python

print("Hello, world!")

Basic Code in Dart

void main() {
  print('Hello, World!');
}
FeaturePythonDart
plain textprint("hi")print('hi');
several itemsprint("Name:", name, "Age:", age)print('Name: $name Age: $age');
string interpolationf"My score is {s}"'My score is $s'
multi-line"""line1\nline2"""'''line1\nline2''';
raw (no escapes)r"C:\path"r'C:\path';

Variables

Leave a Reply