初級 › 文字列と数値を + で連結すると TypeError になる › パターン1
文字列と数値を + で連結すると TypeError になる
Rubyの+演算子は文字列同士、数値同士でしか使えません。
1 age = 20 2 puts "Age: " + ___________ ^
main.rb:2:in `+': no implicit conversion of Integer into String (TypeError)
from main.rb:2:in `<main>'
空欄を埋めて実行を通す
文字列の+は数値を自動で文字列に変換してくれません。to_sで明示的に変換する必要があります。
次の問題