Created
September 25, 2018 13:37
-
-
Save yuyosy/78dff2e2d8fc6b8df850c06b3b096a9f to your computer and use it in GitHub Desktop.
Julia <print>
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
print("a") # 改行なし出力 | |
println("b") # 改行付き出力 | |
println("\n") # \nは改行文字を表す | |
# 文字列 | |
str = "ABC_def_0123456789_HelloWorld!" | |
println(str) | |
# 大文字小文字変換 | |
println(uppercase(str)) # すべて大文字に変換 | |
println(lowercase(str)) # すべて小文字に変換 | |
# 出力 文字列結合 | |
println("str : [", str, "]") | |
println("str : [" * str * "]") | |
# 出力 文字列内に変数埋め込み | |
println("str : [$str]") | |
# Juliaは配列番号は1から | |
println(str[1]) # 文字列strの1番目 A | |
println(str[1:6]) # 文字列strの1~6の範囲 ABC_de | |
println(str[end-15:end]) # 文字列strの最後から15引いた位置から最後まで 6789_HelloWorld! | |
# 文字列と数値表示 | |
x = 10 | |
println(x) | |
println("x = ", x) | |
println("x = " * string(x)) # 数値を文字列に変換 | |
println("x = $x") | |
println("x + 20 = $(x + 20)") # 文字列内で計算し表示 | |
# 数文字列を数値に変換 | |
str_num = "100" | |
int_num = parse(Int, str_num) # Int型に変換 | |
println(int_num + 200) | |
# Cのprintfのような表示マクロ | |
using Printf # ライブラリ読み込み | |
@printf("pi = %.5f\n", pi) | |
# JuliaではUTF-8エンコードではUnicode文字をサポート | |
println("αβγ", "\u03B1", "\u03B2", "\u03B3") # αβγ ユニバーサル文字名でも可能 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment