Python basic syntax

Source: Internet
Author: User

1. Code structure

1) Notes

Single-line Comment: #

Multiline Comment: "" "" "" "

"""

a=11111

Print (a)

"""

2) Basic Data type

Boolean:true and False (Python-case-sensitive Boolean type)

int: integer type (python does not differentiate short,long,int uniformly using int to identify)

STR: string (single quotes, and double quotes to indicate, Python does not make a distinction)

3) Variable Assignment

a=1111111; (variable assignment, define variable without specifying type, type based on function type) Example:print (type (a)) output "Class:int"

x,y=1,2: Multivariate assignment (representing x=1,y=2) if the value of the variable that interacts with two (y,x=1,2 or x,y=2,1)

4) Object Comparison

= = Comparison value itself: example:x,y=1,1 print (x==y)

ID () comparison is memory address example (print (ID (x) =id (y)))

2. Quick Start

Print ("name") #输出一个str

Print ("name", "John Doe") #输出多个元素的值

  Print ("age=" +23) #编译出错 because str and int cannot be directly stitched together (note)

 Name=input ("Please enter name"); print (name) #input是接受控制台输入的参数

3, for the generated type

l1=[1,2,3,4,5]  

L2=[ele+3 for ele in L1 if ele%2] # generates a new collection of element +3 divisible by 2

  

    

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.