Programming Language: Python

Namespace/Package Name: sympy.sets

Class/Type: FiniteSet

Examples at hotexamples.com: 33

Sympy is a Python package that provides a set of tools for symbolic mathematics. The package library that we are discussing here is the sympy.sets module.

The FiniteSet class in sympy.sets creates an ordered set of finite items. It can be used to create sets that have a finite number of items, such as a set of integers or a set of strings.

**Example 1:**

Output:

In this example, we create a FiniteSet object called `s` consisting of the integers 1 to 5. The set is then printed to the console.

**Example 2:**

Output:

The FiniteSet class in sympy.sets creates an ordered set of finite items. It can be used to create sets that have a finite number of items, such as a set of integers or a set of strings.

from sympy import FiniteSet # Create a set of integers s = FiniteSet(1, 2, 3, 4, 5) # Print the set print(s)

Output:

{1, 2, 3, 4, 5}

In this example, we create a FiniteSet object called `s` consisting of the integers 1 to 5. The set is then printed to the console.

from sympy import FiniteSet # Create a set of strings s = FiniteSet('apple', 'banana', 'orange') # Print the set print(s)

Output:

{'apple', 'banana', 'orange'}In this example, we create a FiniteSet object called `s` consisting of the strings "apple", "banana", and "orange". The set is then printed to the console. In both examples, the `sympy.sets` library is used to create the FiniteSet object.

Frequently Used Methods