Python3 Introduction (iii)--python Basic grammar

Source: Internet
Author: User

first, the basic grammar

  1. Line and indent

In Python, you do not use parentheses to represent code class and function definition blocks or process controls.

Code blocks are indented by rows , and the number of indents is variable, but all statements in the block must be indented the same amount.

  As shown below:

A =if a >= 0:    print(a)else:    Print(-a)

  Similarly, it is recommended to have a tab set to 4 spaces (Editor->code sytle)

  2. Notes  

After the "#" sign and to the physical line are part of the comment, the Python interpreter ignores them.

# First Comment Print " Hello, python!. ";  # Second comment

  3. Quotation marks

Python accepts single quotes ('), double quotation marks ("), and three (" or "") references to denote string constants as long as they are the same type of quotation marks that start and end the string.

Sanchong quotes can be used for strings that span multiple lines. For example, all of the following are legal:

' Word '  "This isa sentence. "  "" "This isa paragraph. It ismade up of multiple lines and sentences. """

  4. Semicolon

    Like Scala, semicolons are optional. Generally, you can omit

ii. Types of data

A) Number

b) string

c) List

d) tuples

e) Dictionary

f) Set 

You do not need to display the specified variable type when defining a variable in Python, the following is the typical syntax used by variables in Python:

# Basic use (even if Val in Scala is saved, fully automatic type inference)counter  =          #  int =   1000.0       #  Floating-point name    "John"      #  string

Python3 Introduction (iii)--python Basic grammar

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.