Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

The Type string [7/14]

While a string can be appended to a string by the operator '+', a number or integer cannot be appended to a string.

To append a value of type num or int to a string, the value must first be converted to type string.

Uncomment the erroneous lines to see the error description.

* * *

-- Converting to string--

There are many ways to convert a value to type string. Most commonly, the getter .str performs the desired conversion, but there are many other possibilities.

When using a println statement, it is usually not necessary to join strings by an operator '+', because arguments can simply be separated by a comma.

When the default output format of println statement is not the desired one, it becomes necessary to perform a custom conversion to type string. Making the printout aligned, which is the topic of the next chapter, is one common reason to perform the custom conversion.

Loading...