• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 61
  • Last Modified:

Python 3 code question

I got a Cozmo robot recently and I'm trying to write some code for it, it has a python API.

I am new to python and I'm first trying to understand the sample code they gave.
Here is one example:

import cozmo
from cozmo.util import distance_mm, speed_mmps

def cozmo_program(robot: cozmo.robot.Robot):
  robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()

The line I am curious about is "cozmo_program(robot: cozmo.robot.Robot):"
So, it's a function call. But what is with the Colon ':' in the param?  " robot: cozmo.robot.Robot".  Does it mean that 'robot' is an instance of cozmo.robot.Robot?

In fact I'm also unclear what cozmo.robot.Robot means. Can someone break down that line and explain please?

  • 2
1 Solution
Dan CraciunIT ConsultantCommented:
def function_name(attribute: attribute_type):
That is an annotation.

Dan CraciunIT ConsultantCommented:
The answer is correct.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now