pdf-icon

Text

Example

Program delay and print runtime with text operations

from m5stack import *
from m5ui import *
from uiflow import *
import binascii

string = None
date = None

string = 'hello world'
print(string.upper())
print('hello')
print(string[0])
print(string.count('o'))
print(not len(string))
print(len(string))
print(string.replace('e', 'w'))
print('   m5stack   '.strip())
print('hello world'.strip('h'))
print(str(2500))
print((str('Hi! ') + str(string)))
date = binascii.hexlify('hello').decode()
print(date.encode())
print((binascii.unhexlify(date)).decode())
print("%.0f"%float(date))

Functionality Description

string = 'helloworld'
  • Create text content
print(string.upper())
  • Concatenate text
print(string.upper())
  • Convert text content to uppercase or lowercase
print(string[0])
  • Extract a specified portion of text
print(string.count('o'))
  • Return the number of occurrences of a specified character in the text
print(not len(string))
  • Check if the text is empty
print(len(string))
  • Return the length of the text
print(str(2500))
  • Convert other data types to strings
print((binascii.unhexlify(date)).decode())
  • Decode a string to a specified format
print(date.encode())
  • Convert a string back to a bytes object
date = binascii.hexlify('hello').decode()
  • Encode a string to bytes
print((binascii.unhexlify(date)).decode())
  • Convert a string to a String
print("%.0f"%float(date))
  • Perform string formatting to convert a float to a string without a decimal portion
print('')
  • Print text
print(string.replace('e', 'w'))
  • Replace text content
print('   m5stack   '.strip())
  • Remove leading and trailing whitespace from a string
print('hello world'.strip('h'))
  • Specify characters to remove from the beginning and end of a string
print('hello')
  • Keep the string unescaped, containing all original characters
  • Terminal prompt. Prompt for input with a message
  • Terminal prompt. Customize the prompt for input with a message
On This Page