Fundamentals

Basic Syntax

Significant Indentation

One of the features of Python is that it uses significant indentation (spaces or tabs at the beginning of a line) to define code blocks.

That is, unlike other languages that use curly braces {} or begin/end, in Python indentation is mandatory and defines the structure of the code.

 
if True:
print("This is correctly indented") # Correct
print("This is not correctly indented") # This would cause an error

Comments in MicroPython

Comments allow you to add notes in the code without affecting its execution. They are useful for documenting the code and making it easier to understand.

Single-line comment: The # symbol is used.

# This is a single-line comment
print("Hello, MicroPython") # It can also be used at the end of a line of code


Multi-line comment: Triple quotes (“”” or ”’) can be used.
 

"""
This is a multi-line comment.
"""
print("MicroPython in action")

 

  • Variables and Data Types
  • Operators
  • Conditionals and Loops
  • Functions
  • Exception Handling
  • Modules and Libraries
On this page