1. Python Data type
The reference string when%s represents a reference
%d indicates a reference to an integer
%f represents a quoted number with a decimal point
2. Circulation
The For loop can be used to iterate through all the elements in the list and tuple
For example: For I in List_name
Print I
If the while loop is followed by a true, the loop will go on forever.
The loop does not execute if followed by a fales. And if the break keyword appears in the loop
The loop jumps back immediately, and if continue appears, jump out of the current loop and start the next cycle from the beginning.
For example:
While True:
Word=raw_input (' Please enter: ')
If Word = = ' a ': #输入a immediately returns to the start and re-executes while loop
Continue
elif Word = = ' B ': #输入b则马上跳出while循环并退出
Break
Else
Pass #pass mean do nothing or continue while
3. Use the. Strip () method to delete spaces and line breaks in a string (\ n)
For example: Word = raw_input (' Please enter: ')
#如果输入的内容是 ' A ' or ' a ' with spaces
Word.strip () standard inputs such as #用这个方法就可以获得 ' a '
4, Python has data storage combination list tuple dictionary three styles
List can be deleted and changed to search index slices
Tuples do not support modification but can index slices
A dictionary is a key value stored only by key to find values
5, the processing of documents
The way the file is opened R means read-only w indicates write (if the original file has content will be emptied) a means append (append content after the original file)
Read the file
F=open (' file.txt ', ' R ')
Print F.read ()
#read () indicates that a one-time read-in memory has no structure readlines () represents a row of read-in memory, suitable for reading a configuration file
F.close () #切记 ~ ~ Be sure to close the file after you open it!!!!!
Another way to read a file is to automatically call the close () method to close the file
With open (' file.txt ', ' R ') as F:
Print F.readlines ()
Read () and ReadLines () are not available when reading large files that are not loaded in memory.
With open (' file.txt ', ' R ') as F:
For line in F
Print Line
Write a file
word= ' abc '
F=open (' file.txt ', ' W ')
F.write (Word)
F.flush #将内存中的内容刷新入文件
F.close () #切记!! Be sure to close the file
This article from "Thunderbolt Tofu" blog, declined reprint!
Python Training Day1 Essays