What are the common mistakes of Python's entry? Python Quick Start __python

Source: Internet
Author: User

Python is in sharp contrast to other languages in its Easy-to-understand syntax format, and the most common problem for beginners is not to write in Python's rules, and even programmers with programming experience are apt to write Python code in an inherently mental and grammatical format, making it easy to make mistakes. Here's a list of the easy mistakes you can make to get started with Python.

1. Forget to write a colon

Forget to add ":" After the If, elif, else, for, while, class, Def statement

2. Misuse of "=" to do equivalence comparison

"=" is an assignment operation, and determining whether two values are equal is "= ="

3. Using the wrong indentation

Each line of code in the same code block must maintain a consistent indent

4. Variables are not defined

5. Get list element index location forget to call Len Method

6. Modify the string

A string is an immutable object and does not support modification.

7. String and non-string connection

When a string is concatenated with a non-string, the non-string object must be cast to a string type.

8. Use the wrong index location

The index of the list object starts at 0, and the correct index number is to be mastered.

9. Use a nonexistent key in the dictionary

10. Use the keyword to make variable name

Using keywords as variable names is not allowed in Python.

11. The function is used before the local variable is assigned a value

12. Use the self-added "+ +" self-reduction "--"

There is no self-subtraction operator in Python, which can be replaced with "+ =" and "=".

13. Calling methods in a class incorrectly

The above is to Python3 often make a summary of mistakes, some also apply to Python2, some of the Python2 does not apply, want not to make mistakes, or as little as possible, you need to firmly grasp the basic Python grammar and specific usage.

Related Article

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.