[Python기초] 11. 람다, pass, __doc__속성과 help, 이터레이터 객체

람다(lambda)

  lamda 인자: <구문>
  >>> g = lambda x, y: x*y
  >>> g(2, 3)
  6
  >>> (lambda x: x*x)(3)
  9
  >>>globals()
  {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'g': <function <lambda> at 0x041C8850>}

pass

  >>> while True:
        pass  # 빠져 나가려면 키보드에서 "ctrl + c"를 누름
  KeyboardInterrupt
  >>>
  >>>
  >>> class temp:
        pass

doc, help

이터레이터

  >>> for element in [1, 2, 3]:
	      print(element)
  >>> for element in (1, 2, 3):
	      print(element)
  >>> for key in {'one': 1, 'two': 2}:
	      print(key)
  >>> for char in "123":
	      print(char)
  >>> s = 'abc'
  >>> it = iter(s)
  >>> it
  <str_iterator object at 0x00F121A8>
  >>> next(it)
  'a'