在C#中,我可以轻松编写以下内容:stringstringValue=string.IsNullOrEmpty(otherString)?defaultString:otherString;在Python中是否有快速的方法来做同样的事情,或者我是否坚持使用“if”语句? 最佳答案 在Python2.5中,有AifCelseB它的行为很像C语言中的?:。但是,它不受欢迎的原因有两个:可读性,以及通常有更简单的方法来解决问题的事实。例如,在您的情况下:stringValue=otherStringordefaultString
是否可以在java中的array或string的末尾append单个字符。示例:privatestaticvoid/*methodName*/(){Stringcharacter="a"StringotherString="helen";//thisiswhereineedhelp,iwouldliketomaketheotherStringbecome//helena,isthereawaytodothis?} 最佳答案 1.StringotherString="helen"+character;2.otherString+=ch
是否可以在java中的array或string的末尾append单个字符。示例:privatestaticvoid/*methodName*/(){Stringcharacter="a"StringotherString="helen";//thisiswhereineedhelp,iwouldliketomaketheotherStringbecome//helena,isthereawaytodothis?} 最佳答案 1.StringotherString="helen"+character;2.otherString+=ch