-
-
Save St-Hakky/a55360cc7deffa5d9754fbc32586b6a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"toc": "true" | |
}, | |
"source": [ | |
"# Table of Contents\n", | |
" <p><div class=\"lev1 toc-item\"><a href=\"#String\" data-toc-modified-id=\"String-1\"><span class=\"toc-item-num\">1 </span>String</a></div><div class=\"lev1 toc-item\"><a href=\"#変数を文字列として扱う\" data-toc-modified-id=\"変数を文字列として扱う-2\"><span class=\"toc-item-num\">2 </span>変数を文字列として扱う</a></div><div class=\"lev1 toc-item\"><a href=\"#文字列の結合\" data-toc-modified-id=\"文字列の結合-3\"><span class=\"toc-item-num\">3 </span>文字列の結合</a></div><div class=\"lev1 toc-item\"><a href=\"#character型の結合\" data-toc-modified-id=\"character型の結合-4\"><span class=\"toc-item-num\">4 </span>character型の結合</a></div>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# String" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:28.738000Z", | |
"start_time": "2018-01-24T03:22:27.449Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"string\"" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# 文字列の定義は以下のようにやる。これはPythonと似ている。\n", | |
"str1 = \"string\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:28.751000Z", | |
"start_time": "2018-01-24T03:22:27.600Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"これもstring\"" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# 以下のような形でも定義が可能\n", | |
"str2 = \"\"\"これもstring\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:28.880000Z", | |
"start_time": "2018-01-24T03:22:27.759Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ダブルクオーテーションを\"ここ\"に挟むときはこうする。\n" | |
] | |
} | |
], | |
"source": [ | |
"# ダブルクオーテーションを文章中で使いたいときは、以下のようにしてやる。\n", | |
"println(\"\"\"ダブルクオーテーションを\"ここ\"に挟むときはこうする。\"\"\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.012000Z", | |
"start_time": "2018-01-24T03:22:27.912Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Char" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Pythonだと''でくくった文字列は、stringとして扱われますが、Juliaだとcharacter型として扱われます。\n", | |
"typeof('a')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.458000Z", | |
"start_time": "2018-01-24T03:22:28.072Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "\u001b[91msyntax: invalid character literal\u001b[39m", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[91msyntax: invalid character literal\u001b[39m", | |
"" | |
] | |
} | |
], | |
"source": [ | |
"char1 = 'これはエラーがでます'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# 変数を文字列として扱う\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.462000Z", | |
"start_time": "2018-01-24T03:22:28.384Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"この値は10 です\n" | |
] | |
} | |
], | |
"source": [ | |
"# 変数の先頭に $ を入れることで、変数の中の値を出力できる。\n", | |
"# Pythonよりもシンプルに書ける。\n", | |
"num = 10\n", | |
"println(\"この値は$num です\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.472000Z", | |
"start_time": "2018-01-24T03:22:28.551Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"10 + 10 = 20\n" | |
] | |
} | |
], | |
"source": [ | |
"# こんなこともできるらしい。\n", | |
"println(\"$num + $num = $(num + num)\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# 文字列の結合" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.474000Z", | |
"start_time": "2018-01-24T03:22:28.873Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"私は犬です\"" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# string()のカッコの中に、カンマ区切りで入れていくことで、実現可能らしい。\n", | |
"string(\"私\", \"は\", \"犬です\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.476000Z", | |
"start_time": "2018-01-24T03:22:29.042Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"この値は10です\"" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# 変数も同じ感じで処理してくれる\n", | |
"string(\"この値は\", num, \"です\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:29.478000Z", | |
"start_time": "2018-01-24T03:22:29.207Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"この値は10です\"" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# int型なども同様\n", | |
"string(\"この値は\", 10, \"です\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:30.626000Z", | |
"start_time": "2018-01-24T03:22:29.375Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "\u001b[91mMethodError: no method matching +(::String, ::String)\u001b[0m\nClosest candidates are:\n +(::Any, ::Any, \u001b[91m::Any\u001b[39m, \u001b[91m::Any...\u001b[39m) at operators.jl:424\u001b[39m", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[91mMethodError: no method matching +(::String, ::String)\u001b[0m\nClosest candidates are:\n +(::Any, ::Any, \u001b[91m::Any\u001b[39m, \u001b[91m::Any...\u001b[39m) at operators.jl:424\u001b[39m", | |
"" | |
] | |
} | |
], | |
"source": [ | |
"# ただ、Pythonでは出来る、以下のような文字の連結はできないらしい。\n", | |
"\"これは\" + \"できません\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:30.648000Z", | |
"start_time": "2018-01-24T03:22:29.561Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"これはできる\"" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Pythonだと、文字列が何回も繰り返しで出力される表現で、文字列の連結ができるっぽい。\n", | |
"\"これは\" * \"できる\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# character型の結合" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-01-24T12:22:30.730000Z", | |
"start_time": "2018-01-24T03:22:30.723Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\"ab\"" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# character型の文字を結合させて、文字列にすることも可能っぽい。\n", | |
"char1 = 'a'\n", | |
"char2 = 'b'\n", | |
"string(char1, char2)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.6.0", | |
"language": "julia", | |
"name": "julia-0.6" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.6.0" | |
}, | |
"latex_envs": { | |
"LaTeX_envs_menu_present": true, | |
"autocomplete": true, | |
"bibliofile": "biblio.bib", | |
"cite_by": "apalike", | |
"current_citInitial": 1, | |
"eqLabelWithNumbers": true, | |
"eqNumInitial": 1, | |
"hotkeys": { | |
"equation": "Ctrl-E", | |
"itemize": "Ctrl-I" | |
}, | |
"labels_anchors": false, | |
"latex_user_defs": false, | |
"report_style_numbering": false, | |
"user_envs_cfg": false | |
}, | |
"toc": { | |
"colors": { | |
"hover_highlight": "#DAA520", | |
"navigate_num": "#000000", | |
"navigate_text": "#333333", | |
"running_highlight": "#FF0000", | |
"selected_highlight": "#FFD700", | |
"sidebar_border": "#EEEEEE", | |
"wrapper_background": "#FFFFFF" | |
}, | |
"moveMenuLeft": true, | |
"nav_menu": { | |
"height": "73px", | |
"width": "254px" | |
}, | |
"navigate_menu": true, | |
"number_sections": true, | |
"sideBar": true, | |
"threshold": 4, | |
"toc_cell": true, | |
"toc_section_display": "block", | |
"toc_window_display": true, | |
"widenNotebook": false | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment