Python basic syntax

Source: Internet
Author: User

Identifier

A python identifier is a user-defined name that represents a variable, function, class, module, or any other object. If you specify a name for a programmable entity in Python, it is technically an identifier. The Python language sets a set of rules for programmers to create meaningful identifiers.

    • The first character must be a letter in the alphabet or an underscore _.
    • The other parts of the identifier are made up of letters, numbers, and underscores.
    • Identifiers are case sensitive.

Reserved words

Reserved words are keywords, and we cannot use them as any identifier names. Python's standard library provides a keyword module that can output all the keywords for the current version:

>>> Import keyword
>>> keyword.kwlist
[' False ', ' None ', ' True ', ' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' nonlocal ', ' not ', ' or ', ' Pass ', ' raise ', ' return ', ' Try ', ' while ', ' with ', ' yield ']

Comments

The single-line comment in Python begins with # , with the following example:

# First comment Print ("Hello, python! ")

Execute the above code and the output is:

Hello, python!.

Multiline comments can be in multiple # numbers, plus "and" " (3 single quotes or three double quotes):

# First comment # a second comment " " Third note Fourth Note " " """ Fifth Note, sixth comment """
Print ("Hello, python!")

Execute the above code and the output is:

Hello, python!.

Python basic syntax

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.