The unofficial CircuitPython Reference

str()

description

Python provides builtin functions that explicitly convert between data types. This is commonly known as casting. It is often necessary to cast values when they are used as arguments in a function call. It is generally necessary to cast values whenever a function or other process cannot implicitly convert a given variable to the appropriate datatype. For example when printing a string followed by a numeric type the numeric type must be cast to a string for string concatenation in the print() call to work.

str(variable)  is used to cast numeric data types (integer and float) to strings.

syntax

cast integer to string

my_int = 1605
str(my_int)

cast float to string

my_float = 11.05
str(my_float)

methods

parameters

returns

example code

serial output:

code.py output:

My values = 11.05.1605

see also: