(Iv) python basic grammar

1. Related concepts

1. The expression
expression is something similar to a mathematical formula
such as: 10 + 58--4
expressions are generally only used to calculate some of the results, will not have a material impact on the program
if you enter an expression in interactive mode , the interpreter will automatically output the result of the expression

2. The statement
statement in the program generally need to complete certain functions, such as printing information, access to information, assign values to variables. . .
For example:
Print ()
INPUT ()
A = 10
statement execution procedure will generally have a certain impact
will not necessarily output results of a statement in interactive mode

3. Program (program)
program is a one of the statements and expressions one by one made of. 

4. The functions (function)

Function is a kind of statement, the function designed to perform specific functions of
the function as a long form: XXX ()
classification function:
Built-in functions
- Python functions provided by the interpreter can be used directly in Python
custom function
- by the program members of the self-created function
when we need to complete a certain function, you can go to call built-in functions, custom functions or
two elements of function:
parameters
- content () is a function of the parameters
- can not function parameters, there may be a plurality of parameters, among a plurality of parameters, spaced
return value
- the return value is a function of the result, not all of the functions return the value 

2. syntax conventions

## basic syntax
1. In Python strictly case-sensitive
each line is 2.Python in a statement, wrap each statement to end
3.Python each line statement not too long (specification recommended not more than 80 per line character)
"the Rulers": [80],
4. a statement can write multiple lines, the preparation of multi-line statement back to \ end
5.Python is indented strict language, so do not just write in Python indentation
6. # use in Python to indicate a comment, the contents belong to # comments, the contents of the comment will be ignored by the interpreter
that we can come to an explanation by program notes, we must develop good habits of writing comments
comments requested simple and clear, the general practice will be followed by a space behind #

## literals and variables

A literal is a value, such as: 1,2,3,4,5,6, meaning 'HELLO' literal is represented by the value of the literal may be used directly in the program literals

Variable (variable) can be used to store variables literals, variables and literals are stored indefinite
variable itself has no meaning, it can mean different things depending on the literal

Generally, we in the development, rarely used directly literals are saved literal to a variable, the variable is referenced by literal

## variables and identifiers
## data type
data type refers to the type of a variable worth, that is, which values can be assigned to a variable
value
int
Boolean value
float
complex
string
null

## type checking
## objects (Object)
- Python is an object-oriented language
- everything is an object!
- running them, all data is stored into memory and then run!
- the object is designed to store in memory the data of a specified area
- in fact, the object is a container designed to store data
- as before we learn values, strings, Boolean values, None are objects
- with reference to FIG. 1

Structure ## objects
- each object must hold three types of data
- id (identity)
> the above mentioned id used to identify the object is unique, each object has only the above mentioned id
> object is equivalent to the above mentioned id identity cards No. Like
> by id () function to see the object id
> id is generated by the parser, in the CPython, is the memory address of the object id
> object once created, its id can never be changed

- type (Type)
> type is used to identify the type of the current object belongs
> For example: int str float bool. . .
> Object type determines which functions
> by type () function to see the type of object
> Python is a strongly typed language, the type of the object can not be modified once created


- value (value)
> is a specific value of data stored in the object
> value for some objects may be changed
> object into two categories, mutable objects immutable object
value of the variable objects can change
the value of immutable objects can not be change, before learning objects are immutable objects

## variables and objects
- the object is not directly stored in variables, variables in Python is more like an alias to the object from
- the value stored in the variable is not an object, but id (memory address) objects,
when we when using variables, in fact, to find objects by id in the object
- an object stored in a variable, the variable only when re-assignment will change
- is between independent variables and variables, modify a variable does not affect the other variable

 

## type conversion
- so-called type conversion, to convert an object of type for other objects
- type conversion not change the type of the object itself, but creates a new object based on the current value of the object

## operator (operator)
- arithmetic operators may be one or various operations value or values
- such as +, -, = belong operator
- classification operator:
1. arithmetic operator
2. Assignment operator
3. comparison operators (relational operator)
4. logical operators
The conditional operator (ternary operator)

Guess you like

Origin www.cnblogs.com/panzh/p/12516400.html