These are both valid examples of Python syntax and do the same thing in slightly different ways.


'import microbit' imports the whole module, while 'from microbit import *' imports all classes, functions, and variables from it. The choice depends on user preferences and experience.


Using the 'import microbit' method looks like this:


# Imports go at the top
import microbit

# Code in a 'while True:' loop repeats forever
while True:
    microbit.display.show(microbit.Image.HEART)
    microbit.sleep(1000)
    microbit.display.scroll('Hello')


  • Pros:
    • Less maintenance of your 'import' statements. There's no need to add any extra imports to begin using another item from the module.
    • You can clearly see where the function scroll, show and sleep come from.
  • Cons:
    • Requiring you to type 'microbit' repeatedly in your code can be tedious and repetitive.


# Imports go at the top
from microbit import display

display.scroll('hello')


  • Pros
    • Fewer keystrokes are needed to use the 'display' class.
    • Greater control over accessible module items.
  • Cons:
    • To use a new item from the module, you have to update your import statement. 



# Imports go at the top
from microbit import *

# Code in a 'while True:' loop repeats forever
while True:
    display.show(Image.HEART)
    sleep(1000)
    display.scroll('Hello')


  • Pros:
    • Less typing of function names from within the 'microbit' module.
    • No need to keep updating the import line to use other items from the 'microbit' module.
  • Cons:
    • Less clear what you are importing and how many things you are importing.
    • Some context is lost regarding the 'display' class.


Using 'from microbit import *' is helpful for beginners. With practice and as your code becomes more complex, you may want to revisit the previous two import methods. Your code should always aim to be readable and clear.