Python#
The VEXcode VR Python API Reference explains what each command, method, and function does, what inputs it uses, what it returns, and how it can be used in a project.
Use this reference when you want to understand a command before adding it to a project, check what values it accepts or returns, or compare related commands in a category.
Python commands are used in VEXcode VR Python projects. Blocks projects use the Blocks API section instead.
Python commands in VEXcode VR can depend on the Playground and robot you are using. Some robots include unique methods that do not appear in every Playground.
Playgrounds and Robots in VR#
Use the Playgrounds section to see which robot is used in each Playground and to find Playground-specific setup details, field information, and challenge context.
Use the Robots section to find robot-specific Python pages for robots with unique methods. The Robots pages also show which Playgrounds each robot is used in, so you can tell when a robot-specific method is available in your project.
How to Read a Method Entry#
Most Python entries include the following parts:
Command name - The official name of the command, method, or function.
Description - Explains what the command does and when it is useful.
Usage - Shows the syntax used to write the command in code.
Parameters - Lists the inputs the command accepts and explains what each one does.
Return value - Explains what the command reports back, if it returns a value.
Example code - Shows one way the command can be used in a project.
Common Python API Elements#
Element |
What it means |
|---|---|
Method |
A command called on an object such as |
Function |
A command called directly, such as |
Parameter |
A value passed into a method or function to control what it does. |
Optional parameter |
A parameter that can be left out so the default behavior is used. |
Return value |
A value a command reports back, such as a number, text, or Boolean. |
Basic Python Vocabulary#
Term |
What it means |
|---|---|
Variable |
A name that stores a value, such as |
String |
Text inside quotes, such as |
Integer |
A positive or negative number, such as |
Float |
A number with a decimal, such as |
Boolean |
A value that is either |
Argument |
A value passed into a method or function call, such as |
Example Method Entry#
rotation#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.
Turning right increases the rotation, and turning left decreases the rotation. For example, making two full turns to the right will return a rotation of 720 degrees.
Usage:
drivetrain.rotation(units)
Parameters |
Description |
|---|---|
|
Optional. The rotation unit: |
def main():
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.print("Rotation: ")
brain.print(drivetrain.rotation(DEGREES))
# VR threads - Do not delete
vr_thread(main)