Skip to content

Instantly share code, notes, and snippets.

@computational-sediment-hyd
Created January 8, 2024 01:41
Show Gist options
  • Save computational-sediment-hyd/09728a78ba0d0c24f6f96225407f58c5 to your computer and use it in GitHub Desktop.
Save computational-sediment-hyd/09728a78ba0d0c24f6f96225407f58c5 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "36cede98",
"metadata": {},
"source": [
"# 値渡し"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3755af85",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"source": [
"def func(arg):\n",
" arg += 1\n",
" \n",
"x = 1\n",
"func(x)\n",
"print(x)"
]
},
{
"cell_type": "markdown",
"id": "7cd905da",
"metadata": {},
"source": [
"# 参照渡し(っぽい挙動)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bc066e51",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2]\n"
]
}
],
"source": [
"def func(arg):\n",
" arg[0] += 1\n",
" \n",
"x = [1]\n",
"func(x)\n",
"print(x)"
]
},
{
"cell_type": "markdown",
"id": "4af231a1",
"metadata": {},
"source": [
"# 参考サイト\n",
" - https://www.javadrive.jp/python/userfunc/index3.html\n",
" - https://note.com/crefil/n/n7a0d2dec929b"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.12"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment