[Pyhon] 용어 정리

kkiyou·2021년 5월 24일
0

Python

목록 보기
7/12

참고자료

object(객체)

상태(속성 또는 값)과 정의된 행동(Methods)을 가지고 있는 특정한 자료다.

Any data with state (attributes or value) and defined behavior (methods). Also the ultimate base class of any new-style class.



Function

특정한 값을 반환하는 문자열의 묶음이다. 함수는 본문(fundtion body)에서 실행할 수 있는 0개 이상의 인자들(arguments)을 전달할 수 있다.

A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body. See also parameter, method, and the Function definitions section.



Method

클래스 본문(class body) 내에서 정의된 함수를 일컫는다. 클래스의 인스턴스 속성으로 호출되면, 메소드는 첫 번째 인자(first argument)로 인스턴스 객체(일반적으로 이를 self로 표현한다.)를 가져온다.

A function which is defined inside a class body. If called as an attribute of an instance of that class, the method will get the instance object as its first argument (which is usually called self). See function and nested scope.



Class

사용자가 정의한 객체를 만드는 모형(template)이다.

A template for creating user-defined objects. Class definitions normally contain method definitions which operate on instances of the class.



attribute

.(dot) 표현법을 사용해 참조된 객체의 값이다. 예를들어 객체 o가 속성을 가지고 있으면, o.a로 참조된다.

A value associated with an object which is referenced by name using dotted expressions. For example, if an object o has an attribute a it would be referenced as o.a.



Namespace

Namespace는 딕셔너리 형태의 변수가 저장된 공간이다. 내장함수(built-in), 전역변수(global), 지역변수(local), 객체(object) 등이 저장된다.

The place where a variable is stored. Namespaces are implemented as dictionaries. There are the local, global and built-in namespaces as well as nested namespaces in objects (in methods). Namespaces support modularity by preventing naming conflicts. For instance, the functions builtins.open and os.open() are distinguished by their namespaces. Namespaces also aid readability and maintainability by making it clear which module implements a function. For instance, writing random.seed() or itertools.islice() makes it clear that those functions are implemented by the random and itertools modules, respectively.



Iterable

객체의 요소(member)들을 하나씩 반환할 수 있는 객체를 의미한다. Iterable 객체는 list, str, tuple, range와 같은 모든 유형의 sequence 자료형과 __iter__ method와 __getitem__ method에 의해 정의된 클래스 객체 및 dict, file object 등의 non-sequence 자료형을 의미한다.

An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict, file objects, and objects of any classes you define with an __iter__() method or with a __getitem__() method that implements Sequence semantics.

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.



Iterator

자료의 흐름으로 나타내는 객체이다. 즉 __next__() method로 자료를 연속적으로 호출할 수 있는 객체를 의미한다. iterator는 __next__를 통해 반복적으로 호출하면 스트림에서 연속적인 자료를 반환한다. 그리고 더 이상 자료가 없으면 StopIteration exception을 발생시킨다.

An object representing a stream of data. Repeated calls to the iterator’s __next__() method (or passing it to the built-in function next()) return successive items in the stream. When no more data are available a StopIteration exception is raised instead. At this point, the iterator object is exhausted and any further calls to its __next__() method just raise StopIteration again. Iterators are required to have an __iter__() method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes. A container object (such as a list) produces a fresh new iterator each time you pass it to the iter() function or use it in a for loop. Attempting this with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container.

More information can be found in Iterator Types.

참고자료 1



generator

generator iterator를 반환하는 함수를 의미한다. generator iterator
A function which returns a generator iterator. It looks like a normal function except that it contains yield expressions for producing a series of values usable in a for-loop or that can be retrieved one at a time with the next() function.

Usually refers to a generator function, but may refer to a generator iterator in some contexts. In cases where the intended meaning isn’t clear, using the full terms avoids ambiguity.



generator iterator

An object created by a generator function.

Each yield temporarily suspends processing, remembering the location execution state (including local variables and pending try-statements). When the generator iterator resumes, it picks up where it left off (in contrast to functions which start fresh on every invocation).



sequence

An iterable which supports efficient element access using integer indices via the getitem() special method and defines a len() method that returns the length of the sequence. Some built-in sequence types are list, str, tuple, and bytes. Note that dict also supports getitem() and len(), but is considered a mapping rather than a sequence because the lookups use arbitrary immutable keys rather than integers.

The collections.abc.Sequence abstract base class defines a much richer interface that goes beyond just getitem() and len(), adding count(), index(), contains(), and reversed(). Types that implement this expanded interface can be registered explicitly using register().



EAFP

허락보다 용서를 구하는게 쉽다.
Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many try and except statements. The technique contrasts with the LBYL style common to many other languages such as C



참고자료
혼공-용어노트
혼공-파이썬 용어 총정리2(반복문, 함수, 예외처리)

0개의 댓글