Configure the Python development environment for Mac and concatenate simple strings and Integers
First, install Python 3.4 with HomeBrew. The Python that comes with Apple. If it is developed, forget it. Enter the following command in the terminal.
brew install python3
Next, open Sublime and change the syntax to Python. Input
print ('Hello World')
Note: In Python3, brackets must be added to the print function. For beginners who often use C and Java, they may not be used to using extra points.
After writing this line of code, open the terminal and enter the following code:
python xxx.py
Note that xxx is the complete path of the Python file. After running successfully, you can see the running result in the terminal.
But soon I encountered a problem. For example, I want to output "1 + 2 = 3", where 3 is represented as a variable. Try to run the following code:
print ('100 + 200 = ' + (100+200))
The following error message is displayed:
TypeError: cannot concatenate 'str' and 'int' objects
The reason is that, in Python3.4, strings and numbers cannot be concatenated. The solution is simple. You can use the bytes function to convert the int type to the string type.
The modified code is as follows:
print ('100 + 200 = ' + bytes(100 + 200))
Run it. Everything is OK.
100 + 200 = 300