�֐�

��ʌ`��

def <���O>(����1,����2,...):
    <��>
    return <�l>
��F
>>> def times(x,y):
...     return x * y
...
>>> times(2, 4)
8
>>> times('Ni',4)
'NiNiNiNi'

�֐��̃X�R�[�v�K��

���O(�ϐ����C�֐���)�̗L���͈�
Python �ł� �l�����������_�� ���O�����݂��J�n����D
�֐������ő�����ꂽ���O�͂��̊֐����ŗL��(���[�J���E�X�R�[�v) (�t�̓O���[�o���E�X�R�[�v)

���O�����FLGB �K��

Local, Global, Builtin �̏��Ŗ��O����������D
��
>>> x = 99
>>> def f(y):
	z = x + y
	return z

>>> f(1)
100
global ���g����
>>> x = 99
>>> def g(y):
	global x
	x = x + y

	
>>> g(1)
>>> x
100

�����n��

>>> def changer(x, y):
	x = 2
	y[0] = 'spam'

	
>>> X = 1
>>> L = [1, 2]
>>> changer(X, L)
>>> X, L
(1, ['spam', 2])
���ۂɑ���������Ȃ��āC��Ɠ������ʂɂȂ邱�Ƃ��m���߂Ă݂悤�D

return

return �� �C�ӂ̃I�u�W�F�N�g��Ԃ����Ƃ��ł���D
>>> def multiple(x, y):
	x = 2
	y = [3, 4]
	return x, y

>>> X = 1
>>> L = [1, 2]
>>> X, L = multiple(X, L)
>>> X
2
>>> L
[3, 4]

�����̑Ή��t��

>>> def func(spam, eggs, toast=0, ham=0):
	print (spam, eggs, toast, ham)

	
>>> func(1,2)
(1, 2, 0, 0)
>>> func(1, ham=1, eggs=0)
(1, 0, 0, 1)
>>> func(spam=1, eggs=0)
(1, 0, 0, 0)
>>> func(toast=1, eggs=2, spam=3)
(3, 2, 1, 0)
>>> func(1, 2, 3, 4)
(1, 2, 3, 4)
>>> func(0)
Traceback (innermost last):
  File "", line 1, in ?
    func(0)
TypeError: not enough arguments; expected 2, got 1
�•ψ����̗�(inter2.py��p�ӂ��Ă���)
>>> from inter2 import intersect, union
>>> s1, s2, s3 = "SPAM", "SCAM", "SLAM"
>>> intersect(s1, s2), union(s1, s2)
(['S', 'A', 'M'], ['S', 'P', 'A', 'M', 'C'])
>>> intersect([1,2,3], (1,4))
[1]
>>> intersect(s1, s2, s3)
['S', 'A', 'M']
>>> union(s1, s2, s3)
['S', 'P', 'A', 'M', 'C', 'L']

�⑫

�����_��

��s�ŏ����֐�
>>> f = lambda x, y, z: x + y + z
>>> f(1,2,3)
6

apply

�g�p�@
if test:
    action, args = func1, (1,)
else:
    action, args = func2, (1, 2, 3)
...
apply(action, args)

map

���X�g����x�ɍ��D
>>> counters = [1, 2, 3, 4]
>>> map(lambda x: x + 3, counters)
[4, 5, 6, 7]

�l��Ԃ��Ȃ��֐�

>>> list = [1, 2, 3]
>>> list = list.append(4)
>>> list
>>> list = [1, 2, 3]
>>> list.append(4)
>>> list
[1, 2, 3, 4]

���K���

  1. Python�̑Θb�I�v�����v�g�ɑ΂��āC�������P�‚����󂯂Ƃ��āC����� ��ʂɕ\������֐��������Ȃ����D�����āC���̊֐��ɕ�����C�����C���X�g�C �^�v���C�f�B�N�V���i����n���ČĂяo���Ă݂Ȃ����D�܂��C�����������n���Ȃ� �ꍇ�ƈ������Q�ˆȏ�n�����ꍇ�̃G���[���b�Z�[�W���m���߂Ȃ����D
  2. adder�Ƃ������O�̊֐������W���[���t�@�C���ɍ쐬���Ȃ����D �����ŁCadder �͂Q�‚̈������󂯂Ƃ�C�����̘a�i���邢�͘A���j��Ԃ� �֐��Ƃ���D���ɁC���̃t�@�C���̍Ō�ɂ��܂��܂Ȍ^�̃I�u�W�F�N�g��n���� ���̊֐����Ăяo���R�[�h��lj����Ȃ����D���̃t�@�C�����X�N���v�g�Ƃ��� �I�y���[�e�B���O�V�X�e���̃R�}���h���C��������s���Ȃ����D���ʂ̕\���ɂ� print �����K�v�ł��邱�Ƃ��m���߂Ȃ����D
  3. ��̖��ō쐬���� adder �֐�����ʉ����āC�C�ӂ̌��̈����̑��a ���v�Z����悤�ɂ��Ȃ����D
  4. �Q�‚̃f�B�N�V���i���̌���(union)��Ԃ��悤�� addDict �Ƃ����֐��� �쐬���Ȃ����D
  5. �񎟕������̉����^�v���ŕԂ��֐��������Ȃ����D�����ŁC�����Ƃ��Ă� a * x**2 + b * x + c = 0 �̌W�� a,b,c �ŗ^������̂Ƃ���D �܂��C���������v�Z����֐� sqrt() �� math ���W���[���Ɋ܂܂�Ă���D