Python's operator.not_ in TypeScript

✓ Verified: Python 3.12
Examples tested against actual runtime. CI re-verifies continuously. Only documented examples are tested.
Rosetta Stone: python/truth

How to use

Install via yarn add locutus and import: import { not_ } from 'locutus/python/operator/not_'.

Or with CommonJS: const { not_ } = require('locutus/python/operator/not_')

Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern.

Examples

These examples are extracted from test cases that automatically verify our functions against their native counterparts.

#codeexpected result
1not_([])true
2not_(NaN)false

Notes

  • Uses Python truthiness rules instead of raw JS Boolean coercion.

Dependencies

This function uses the following Locutus functions:

Here's what our current TypeScript equivalent to Python's operator.not_ looks like.

import { pythonNot } from '../_helpers/_operator.ts'

export function not_(a: unknown): boolean {
// discuss at: https://locutus.io/python/operator/not_/
// parity verified: Python 3.12
// original by: Kevin van Zonneveld (https://kvz.io)
// note 1: Uses Python truthiness rules instead of raw JS Boolean coercion.
// example 1: not_([])
// returns 1: true
// example 2: not_(NaN)
// returns 2: false

return pythonNot(a)
}

Improve this function

Locutus is a community effort following The McDonald's Theory: we ship first iterations, hoping others will improve them. If you see something that could be better, we'd love your contribution.

View on GitHub · Edit on GitHub · View Raw


Help us add more

Got a rainy Sunday afternoon and a taste for a porting puzzle?

We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.

« More Python operator functions


Star