[PYTHON] Part 1 Attempt to code mathematics (∈)

This post is a Japanese translation of Mathematics to code: ∈-by Kohei Shingai.

is.element.of.2.jpg

is.element.of.1.jpg https://www.instagram.com/p/BQvOfRygJCA

Check x ∈ A with a function of R

Use ʻis.element (x, A)`,

A <- c(1:5)
#Set A is[1, 2, 3, 4, 5]

is.element(1, A) #result: TRUE
#That is, 1 ∈ A- {1, 2, 3, 4, 5}whether?

is.element(6, A) #result: FALSE
#That is, 6 ∈ A- {1, 2, 3, 4, 5}whether?

Check x ∈ A with standard Python operators

Use x in A,

A = set([1, 2, 3, 4, 5]) #Set A

1 in A #result: True
#That is, 1 ∈ A- {1, 2, 3, 4, 5}whether?

6 in A #result: False
#That is, 6 ∈ A- {1, 2, 3, 4, 5}whether?

Check x ∈ A in Ruby method

Use ʻA.include? X`,

A = (1..5).to_a
#Set A is[1, 2, 3, 4, 5]

A.include?1 #result: true
#That is, 1 ∈ A- {1, 2, 3, 4, 5}whether?

A.include?6 #result: false
#That is, 6 ∈ A- {1, 2, 3, 4, 5}whether?

Check x ∈ A in a JavaScript expression or method

Use ʻA.indexOf ()! = -1 or ʻA.includes (x),

A = [1, 2, 3, 4, 5] //Set A

A.indexOf(1) != -1 //result: true
//That is, 1 ∈ A- {1, 2, 3, 4, 5}whether?

A.indexOf(6) != -1 //result: false
//That is, 6 ∈ A- {1, 2, 3, 4, 5}whether?

A.includes(1) //result: true -ES2016 or later
//That is, 1 ∈ A- {1, 2, 3, 4, 5}whether?

A.includes(6) //result: false -ES2016 or later
//That is, 6 ∈ A- {1, 2, 3, 4, 5}whether?

Recommended Posts

Part 1 Attempt to code mathematics (∈)
Rewrite Python2 code to Python3 (2to3)
Introduction to PyQt4 Part 1
Attempt to automate Pricone R
Tool to check code style
Command to generate QR code
Set VS Code to PyCharm.
Attempt to automatically adjust the speed of time-lapse movies (Part 2)
Introduction to Ansible Part ③'Inventory'
Convert python 3.x code to python 2.x
Introduction to Ansible Part ④'Variable'
Character code † darkness † encounter report part1
Java with Visual Studio Code (Part 2)
Golang is difficult to translate. .. .. (Part 1)
Introduction to Ansible Part 2'Basic Grammar'
Introduction to Python Hands On Part 1
Code to randomly generate a score
Added code snippet functionality to django-ckeditor
Project Euler 4 Attempt to speed up
To maintain code quality in PyCharm
Aiming to acquire E qualification ~ Part 1
Linux commands related to character code
How to run TensorFlow 1.0 code in 2.0
Migrate from VS Code to PyCharm
Introduction to Ansible Part 1'Hello World !!'
How to authenticate with Django Part 2
How to authenticate with Django Part 3