Note python, the basic data types, operators

Note

In python, comments are divided into single-line comments and multiline comments:

Single-line comments begin with the # symbol

E.g:

# This is a comment

print('hello world')

Multi-line comments with three single quotes' '' or three double quotation marks "" "enclose the annotation content

E.g:

'''

This is a multi-line comments

This is a multi-line comments

This is a multi-line comments

'''

"""

This is a multi-line comments

This is a multi-line comments

"""

Basic data types

A digital type

1, int int

Role: Record age, grade, number

Example: age = 18

2, float type

Role: payroll records, height, weight

Example: height = 1.80

Second, the string

Action: state record described properties

Definition: single quotes, double quotes, triple quotes a series of characters contained

Example: name = 'tom'

Third, the list

Action: isoforms in accordance with the value of the attribute (the value corresponding to the index, the index starts from 0 and is representative of the position), and can be taken a certain position specified by the plurality of location history

Definition: a plurality of spaced values ​​of any type comma within []

Example: list = [ 'bob', 18]

Fourth, Dictionary

Action: recording a plurality of different values ​​of attributes

Is defined: {} in the plurality of elements separated by a comma, and every element by key value composed of, our value is the value stored, may be any type, is a key functional descriptive value, typically type str

例:dic={'name':'alx','age':18}

V. Boolean type bool: True, False

Role: Analyzing

Stressed: all values ​​are built boolean value, where 0, none, empty Boolean value is False, others are True

Operators

First, arithmetic operators

+ - *  /   // 

Second, comparison operators

>  ==  !=   >=

Third, the assignment operator

1, the incremental assignment: age + = 1

2, the cross assignment: x, y = y, x

3, the chain assignment: x = y = z = 10

4, extract assignment: x, y, z = list, the right and left of the variable name values ​​are included in one correspondence

Fourth, the logical operators

and: logic and for connecting the left and right conditions, conditions are about two to true, the final result is true

or: logic or, for connecting the left and right two conditions, as long as there is about a two conditions is True, the final result is True

not: negation

Fifth, the identity of the operator

==: determining whether the value is equal to

is: determining whether the same id

Equal to the id, the same constant value

Equal value, id not necessarily the same

Guess you like

Origin www.cnblogs.com/zhangdajin/p/10947471.html