python#1 Pythonの重複可能オブジェクトについて
9447 ワード
シーケンスオブジェクトと重複可能オブジェクトの違い
Iterableオブジェクト
Iterables can be used in a for loop and in many other places where a sequence is needed (zip(), map(), …). When an iterable object is passed as an argument to the built-in function iter(), it returns an iterator for the object. This iterator is good for one pass over the set of values. When using iterables, it is usually not necessary to call iter() or deal with iterator objects yourself. The for statement does that automatically for you, creating a temporary unnamed variable to hold the iterator for the duration of the loop. See also iterator, sequence, and generator.
https://docs.python.org/3/glossary.html#term-iterable
>>> import collections
# iterable 한 타입
>>> var_list = [1, 3, 5, 7]
>>> isinstance(var_list, collections.Iterable)
True
>>> var_dict = {"a": 1, "b":1}
>>> isinstance(var_dict, collections.Iterable)
True
>>> var_set = {1, 3}
>>> isinstance(var_set, collections.Iterable)
True
>>> var_str = "abc"
>>> isinstance(var_str, collections.Iterable)
True
>>> var_bytes = b'abcdef'
>>> isinstance(var_bytes, collections.Iterable)
True
>>> var_tuple = (1, 3, 5, 7)
>>> isinstance(var_tuple, collections.Iterable)
True
>>> var_range = range(0,5)
>>> isinstance(var_range, collections.Iterable)
True
# iterable하지 않은 타입
>>> var_int = 932
>>> isinstance(var_int, collections.Iterable)
False
>>> var_float = 10.2
>>> isinstance(var_float, collections.Iterable)
False
>>> var_none = None
>>> isinstance(var_none, collections.Iterable)
False
このような結果が得られた.リンクテキストReference
この問題について(python#1 Pythonの重複可能オブジェクトについて), 我々は、より多くの情報をここで見つけました https://velog.io/@clayryu328/python1-파이썬의-반복-가능한-객체들에-대해서テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol