The unofficial CircuitPython Reference

string

description

Python has 5 primitive classes of data: string, integer, float, boolean, and complex. There is no need to declare a specific data type for variable as Python will infer the data type at assignment.

The string type stores text in Python. It is declared with the = assignment operator followed by a string of text contained in 'single' or "double" quotation marks. There is no functional difference between single and double quoted strings.

When declaring a variable in Python it must begin with a letter and the name may only contain letters, numbers, and underscores. For the sake of readability it is conventional to use all lower case letters and numbers for variable names with underscores to separate words. It is best to avoid I and O for single letter variable names as they can look like 1 and 0. Python does not have a constant keyword and there is therefore no enforced constant but again for readability it is conventional to name CONSTANTS with all caps and underscores between words.

syntax

declare a string (implicit)

my_string = "This is a string of text"

declare multiple strings

str1, str2, str3 = "A", "B", "C"

methods

parameters

returns

example code

serial output:

code.py output:

this is a string of text

A

B

C

see also: