Mac configures the Python development environment and implements simple string and integer stitching

Source: Internet
Author: User

First install the Python version 3.4 with homebrew. Apple's own python, the development of words or forget it. Enter this line of command in the terminal.

install python3

Next open the sublime, and the syntax is changed to Python. Input

print (‘Hello World‘)

Note that in Python3, the print function needs to be enclosed in parentheses. For beginners who often use C,java, they may not be accustomed to using semicolons.

After you finish writing this line of code, open the terminal and enter the following code:

python xxx.py

Note that xxx here is the full path to the Python file. After successful operation, you can see the results of the operation in the terminal.

But soon there was a problem, like I wanted to output "1+2=3", where 3 was represented as a variable. Try to run the code like this:

print (‘100 + 200 = ‘ + (100+200))

Get the error message:

Typeerror:cannot concatenate ' str ' and ' int ' objects

The reason is that the Python3.4 version does not allow strings and numbers to be stitched together. The workaround is simple, by converting the int type to a string type through the bytes function.

The modified code is:

print (‘100 + 200 = ‘ + bytes(100200))

Run, everything OK.

100 + 200 = 300

Mac configures the Python development environment and implements simple string and integer stitching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.