Objective
It is well known that Python is not like JS or PHP in the weakly typed language when strings are connected automatically convert the type, if the string and the number of direct concatenation will directly error.
As in the following code:
# coding=utf8str = ' Your score is: ' num = 82text = str+num+ ' points | Joan Taiwan Blog ' Print text '
Execution results
Direct error: Typeerror:cannot concatenate ' str ' and ' int ' objects
To resolve this method, you can use the bytes function to convert the int to string type only if you have to convert num to character strings in advance.
Code:
# coding=utf8str = ' Your score is: ' num = 82num = bytes (num) Text = str+num+ ' points | Joan Taiwan Blog ' Print text '
The results are done:
Summarize
The above is to solve the Python string and the number of errors in the concatenation of the entire content, I hope that the content of this article for you to learn or use Python can help, if there are questions you can message exchange.