Python3. Simple error Handling in X

Source: Internet
Author: User

1.print

>>> print ' Hello World '
Syntaxerror:missing parentheses in call to ' print '
>>>

After the Python version was updated, a lot of functions were removed from the 3.X version, in 3. In the X version of Python, print needs parentheses

Such as:

>>> print (' Hello World ')
Hello World
>>>

Another: When the data is output as a group, python2.x directly after the output data need to add ",", but the use of this method in python3.x is not valid, you should use the following code:

>>> print (item, end= "")

2.input

>>> myname=raw_input (' Ener Your Name: ')
Traceback (most recent):
File "<pyshell#129>", line 1, in <module>
Myname=raw_input (' Ener Your Name: ')
Nameerror:name ' raw_input ' is not defined
>>>

Same as 1, due to version issue. Can be replaced directly with input

Such as:

>>> myname=input (' Ener Your Name: ')
Ener your Name:cookie
>>>

3.decimal

>>> Print (decimal. Decimal (' 1.1 '))
Traceback (most recent):
File "c:/users/cookie/desktop/bb.py", line 2, <module>
Print (decimal. Decimal (' 1.1 '))
Nameerror:name ' decimal ' is not defined
>>>

Error ' decimal ' not defined, import decimal package can

Such as:

>>> Import Decimal
>>> Print (decimal. Decimal (' 1.1 '))
1.1
>>>

Python3. Simple error Handling in X

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.