内容简介:http://stackoverflow.com/questions/14895594/cant-convert-fixnum-into-string-typeerror
我打了一个’不能将Fixnum转换成String(TypeError)’错误,而它似乎很简单,我不知道如何解决它.我认为我的逻辑是声音 – 将输入的字符串变量转换为整数,然后执行基本操作 – 但显然我缺少一些关键的信息.
puts 'What is your favourite number?' favenum = gets.chomp better = favenum.to_i + 1 puts 'Yeah '+favenum+' is nice enough but '+better+' is bigger and better by far! Think on.'
已经尝试寻找一个答案,但同样的错误的例子现在有超出我的基本的红宝石技能.
Ruby(与其他一些语言不同)在String#方法中的操作数时不会将对象转换为字符串.手动转换为字符串:
puts 'Yeah ' + favenum.to_s + ' is nice enough but ' + better.to_s + ' is bigger and better by far!'
或使用字符串插值(注意双引号):
puts "Yeah #{favenum} is nice enough but #{better} is bigger and better by far!"
http://stackoverflow.com/questions/14895594/cant-convert-fixnum-into-string-typeerror
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- golang中为什么[]string 不能直接转换[]interface{}
- ios – xcode 6 beta 4 – MessageComposeResult不能转换为OptionalNilComparisonType
- 答读者问:为什么 Go 里面不能把任意切片转换为 []interface{} ?
- ApiCloud开发SuperWebView——极光推送不能监听通知内容以及不能跳转的问题
- 有的便宜不能占
- golang不能使用debug
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Text Processing in Python
David Mertz / Addison-Wesley Professional / 2003-6-12 / USD 54.99
Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing som......一起来看看 《Text Processing in Python》 这本书的介绍吧!