w3resource
w3resource logo

Python: set() function

(追記) (追記ここまで)
(追記) (追記ここまで)

set() function

The set() function is used to create a set object.

Read more about set from Python Set and Python Exercises.

Version:

(Python 3.2.5)

Syntax:

set([iterable])

Parameter:

Name Description Required /
Optional
iterable A sequence. Optional

Return value:

An empty set without any parameters.
A set constructed from the given iterable parameter.

Example: Python set() function

# empty set
print(set())
# from string
print(set('Python'))
# from tuple
print(set(('e', 'x', 'e', 'r', 'c', 'i','s','e')))
# from list
print(set(['a', 'e', 'i', 'o', 'u']))
# from range
print(set(range(7)))

Output:

set()
{'h', 'y', 'n', 't', 'o', 'P'}
{'s', 'i', 'r', 'c', 'e', 'x'}
{'i', 'o', 'a', 'e', 'u'}
{0, 1, 2, 3, 4, 5, 6}

Pictorial Presentation:

Python: Built-in-function - set() function

Pictorial Presentation:

Python: Built-in-function - set() function

Python Code Editor:

[フレーム]

PREV : round()
NEXT : setattr()

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.

(追記) (追記ここまで)


(追記) (追記ここまで)
(追記) (追記ここまで)


AltStyle によって変換されたページ (->オリジナル) /