First, Python overview:
(a), Python introduction:
1.python Origin:
Guido van Rossum, a Python rosam, was founded at the end of 1989.
In early 1991, Python released its first public release
A research project for the purpose of its creation in order to better complete the CWI (National Institute for Mathematics and Computer science) in the Netherlands
Features of 2.python:
Advanced: Advanced data structure to shorten development time and code volume
Object-oriented: Adds new vitality to structured and procedural programming that separates data and logic
Upgradeable: Provides a basic development module that can be used to develop software for code reuse
Extensible: Organize management by separating it into multiple files or modules
Portability: Python is written in C and, because of the portability of C, Python can run on any platform with an ANSI C compiler
Easy to learn: Python has fewer keywords, simple structure and clear syntax
Easy to read: No other language is commonly used to access variables, define blocks of code, and perform pattern-matching imperative symbols
Memory Manager: The memory manager is the responsibility of the Python interpreter
Second, Python start:
(a), Python syntax structure:
1. Statement block indentation:
The Python code block expresses the code logic with indentation alignment instead of curly braces
2. Program output:
Print prints data to the screen
print ' Hello World '--->Hello World
3. Program Input:
Use the Raw_input () function to read user input data
4. Notes:
Use the # symbol to mark comments
5. Document string:
Can be used as a special note, a simple description using single or double cited, a longer description using the three-lead
Quotation marks: Single-lead, double-lead, three-lead
Single citation '
Double citation ""
Three-lead "or" "" "" can be wrapped.
(ii), Python variables:
1. Variable definition:
1). Variable Name conventions:
Use alphanumeric underscores, starting with letters or underscores
Note: Python is a dynamic type language, that is, you do not need to declare the type of a variable beforehand
2). Variable assignment:
The type and value of the variable are initialized at the moment of assignment.
Variable assignment is performed by an equal sign, and Python also supports incremental assignment
3). Operator:
Standard operators:
+ - * / // % **
Comparison operators:
> >= = = = <= < ps: No matter numbers or letters
Logical operators:
And not OR
Iii. python data type: (type () query data type)
(a), number:
1. Basic Number types:
int by signed integer
Long Integer
BOOL Boolean value
float floating point number
Complex plural
2. Digital representation:
The number is used by default in decimal:
Numbers start with 0 to indicate 8 binary numbers (more important)
Numbers start with a 0x or 0X representation of 16 binary
Numbers start with 0b or 0 B to indicate 2 binary
#################################
#修改文件权限 (using 8 binary)
Import OS
Os.chmod (' Test.txt ', 00644)
#################################
(b), string:
1. Define the string:
Pyhton strings are defined as character sets between quotes, Python does not differentiate between characters and strings
2. String slices:
Use the index operator [] and the slice operator [:] to get substrings
The index of the first character is 0, and the index of the last character is-1
The substring contains the starting subscript in the slice, but does not contain the end subscript
#################################
#对字符串切片
Py= ' 0123456789abcdef '
Print Py[1:4]
1234//starting from 0, not including fourth digit
Print Py[5:]
56789abcdef//starting from 5th to last
Print Py[:5]
01234 //from No. 0 place to 5th position, excluding 5th digit
#################################
3. String continuous operation:
Multiple strings can be stitched together using the + sign
Use the * number to repeat a string multiple times
(c), list: (a variable to store multiple values) []
1. Define the list:
You can use a list as a normal "array" to hold any number of arbitrary types of Python objects
The list also supports subscript and slice operations, where items can be changed
2. List operations:
Use in or not to determine a member relationship
To append an element to the list using the Append method
#################################
A=[11,22,33]
Print a--->[11, 22, 33]
Print a[0]--->11
Print a[1]--->22
Print a[2]--->33
Print A[0:2] --->[11, 22]
a[0]==99
Print a--->[99, 22, 33]
A.append ()//use in or not to determine member relationships
Print a--->[11, 22, 33, 44]
Print in a--->True//Append elements to the list
#################################
(iv), tuple: (a variable to store multiple values) ()
1. Definition and operation of the tuple:
You can think of tuples as a "static" list, and once a tuple is defined successfully, you cannot modify
#################################
A= (11,22,33)
Print a[0]--->11
#################################
(v), Dictionary: (one variable to store multiple values) {}
1. Definition and operation of the dictionary:
A dictionary is a mapping data type consisting of a key-value (Key-value), which is not supported by key values.
#################################
a={' l ': ' X ', ' m ': ' Y ', ' n ': ' Z '}
Print a[' l ']--->x
a[' l ']= ' m '
a[' P ']= ' n '
Print a---> {' P ': ' N ', ' m ': ' Y ', ' l ': ' m ', ' n ': ' Z '}
#################################
(vi), data type comparison:
1. Classify by Storage model:
Scalar types: Numbers, strings
Container type: list, tuple, dictionary
2. Classification by Update Model:
Mutable type: list, dictionary
Immutable types: Numbers, strings, tuples
3. Classification by Access model:
Direct access: Digital
Sequential access: strings, lists, tuples
Map Access: Dictionaries
Iv. Judgment statement:
(a), if statement:
1.if statement Syntax structure:
Syntax for standard if condition statements:
If expression:
If_suite
Else
Else_suite
If the value of the expression is not 0 or a Boolean value of True, the code group If_suite, otherwise execution else_suite
2.if Statement Example parsing:
True if the expression number is a value other than 0
The values for empty strings, empty lists, empty tuples, and empty dictionaries are all flase
(b), extend the IF statement:
1. Extend the IF statement structure:
1). Expand the syntax of the IF condition statement:
If expression1:
If_suite
Elif expression1:
Elif_suite
Else
Else_suite
2). No substitute for Switch/case
2. Extended If statement Example parsing:
For multiple branches, only one of the branches that satisfies the condition is executed
Module official website: PyPI Python module Web site Https://pypi.python.org/pypi
Website open source, download do not need to register an account for free, upload need to register an account
Python three-day simple learning Day1