Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

types

import types

Provides type validation and conversion capabilities

This module is wrapper around the builtin functions where applicable and does and return the same thing as the builtin alternative.

The types API

Every public name in types, wherever it is declared. Each links to the page that documents it.

NameKindSummary
types.alphafunctionReturns true if the value is a character and alphabetic, otherwise returns false.
types.boolfunctionReturns true if the value is a boolean or false otherwise.
types.bytesfunctionReturns true if the value is a bytes or false otherwise.
types.callablefunctionReturns true if the value is a callable function or class and false otherwise.
types.charfunctionReturns true if the value is a single character or false otherwise.
types.dictfunctionReturns true if the value is a dictionary or false otherwise.
types.digitfunctionReturns true if the value is a character and digit, otherwise returns false.
types.filefunctionReturns true if the value is a file or false otherwise.
types.functionfunctionReturns true if the value is a function or false otherwise.
types.instancefunctionReturns true if the value is an instance the given class, false otherwise.
types.intfunctionReturns true if the value is an integer or false otherwise.
types.is_a_classfunctionReturns true if the value is a class or false otherwise.
types.iterablefunctionReturns true if the value is an iterable or false otherwise.
types.listfunctionReturns true if the value is a list or false otherwise.
types.numberfunctionReturns true if the value is a number or false otherwise.
types.objectfunctionReturns true if the value is an object or false otherwise.
types.offunctionReturns the name of the type of value
types.stringfunctionReturns true if the value is a string or false otherwise.

Functions

of()

types.of(value) -> string

Returns the name of the type of value

Parameters

  • value (any)

Returns string

Note: method implemented as part of core language features

digit()

types.digit(value: string) -> bool

Returns true if the value is a character and digit, otherwise returns false.

Parameters

  • value (string)

Returns bool

alpha()

types.alpha(value: string) -> bool

Returns true if the value is a character and alphabetic, otherwise returns false.

Parameters

  • value (string)

Returns bool

int()

types.int(value) -> bool

Returns true if the value is an integer or false otherwise.

Parameters

  • value (any)

Returns bool

bool()

types.bool(value) -> bool

Returns true if the value is a boolean or false otherwise.

Parameters

  • value (any)

Returns bool

number()

types.number(value) -> bool

Returns true if the value is a number or false otherwise.

Parameters

  • value (any)

Returns bool

Note: this method also returns true for integers.

char()

types.char(value) -> bool

Returns true if the value is a single character or false otherwise.

Parameters

  • value (any)

Returns bool

string()

types.string(value) -> bool

Returns true if the value is a string or false otherwise.

Parameters

  • value (any)

Returns bool

bytes()

types.bytes(value) -> bool

Returns true if the value is a bytes or false otherwise.

Parameters

  • value (any)

Returns bool

list()

types.list(value) -> bool

Returns true if the value is a list or false otherwise.

Parameters

  • value (any)

Returns bool

dict()

types.dict(value) -> bool

Returns true if the value is a dictionary or false otherwise.

Parameters

  • value (any)

Returns bool

object()

types.object(value) -> bool

Returns true if the value is an object or false otherwise.

Parameters

  • value (any)

Returns bool

function()

types.function(value) -> bool

Returns true if the value is a function or false otherwise.

Parameters

  • value (any)

Returns bool

is_a_class()

types.is_a_class(value) -> bool

Returns true if the value is a class or false otherwise.

Parameters

  • value (any)

Returns bool

file()

types.file(value) -> bool

Returns true if the value is a file or false otherwise.

Parameters

  • value (any)

Returns bool

iterable()

types.iterable(value) -> bool

Returns true if the value is an iterable or false otherwise.

Parameters

  • value (any)

Returns bool

callable()

types.callable(value) -> bool

Returns true if the value is a callable function or class and false otherwise.

Parameters

  • value (any)

Returns bool

instance()

types.instance(value, type: type) -> bool

Returns true if the value is an instance the given class, false otherwise.

Parameters

  • value (any)
  • type (type)

Returns bool


2021, Richard Ore and Zuri contributors