Contenido del Curso
Introduction to Python | Mobile-Friendly
Introduction to Python | Mobile-Friendly
Converting
Good! But what if you want to concatenate a string with a numerical value? Like, Level: 5. If you try to apply the same approach as in the previous chapter, you will get an error that you can not concatenate str
and int
types.
So, how do you avoid this problem? You cannot convert text into a numerical type, but you can do the opposite. To convert a variable into a string type, use the str()
function, putting the value/variable you want to convert within the parentheses. For instance, let's represent the example above in the code.
Note that we left a blank space to the right of the colon sign within the
string
variable.
The variables chapter
and section
represent the current chapter position. You need to output the message using the print()
function two times in the following format:
¿Todo estuvo claro?