Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active November 10, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/5b02475b4f8a4eb850f4cd4017061a2c to your computer and use it in GitHub Desktop.
Save kurozumi/5b02475b4f8a4eb850f4cd4017061a2c to your computer and use it in GitHub Desktop.
Pythonでは関数のデフォルト値は最初の呼び出ししか評価されない。
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def hoge(arg=[]):\n",
" arg.append(\"hoge\")\n",
" return arg"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['hoge']\n"
]
}
],
"source": [
"h = hoge()\n",
"print(h)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['hoge', 'hoge']\n"
]
}
],
"source": [
"h = hoge()\n",
"print(h)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['hoge', 'hoge', 'hoge']\n"
]
}
],
"source": [
"h = hoge()\n",
"print(h)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment