· Define a nice Python bytecode
#/usr/bin/env python
#_ *_ Coding:utf-8 _*_
· Three built-in parameters: Type,help,dir
Type: You can see what type of variable it belongs to
Help: Point out the use of parameters and detailed explanation of the method
Dir: Enumeration of the use of parameters, not involving a detailed explanation
· Import: Define the use of XXX blocks
· The single "=" number is an assignment, and the double "= =" number indicates a comparison
· Python is sensitive to capitalization
· Common Basic data types:
int: integer defines the variable: a = 1, b = 1------is actually the definition array
Boolean: Bourbourg value defines whether the variable is true or false: A = Ture or a = FALSE; defines a Boolean value the first word must be capitalized----------false Ture
String: Character string defines variable: a = "123sdad"---use double quotation mark "" box.
Lists: List definition variables: a = [1,2,3,4]
Tuple: meta-ancestor tuple definition variable: a = (1,2,3,4)
Dict: Dictionary
· name = input () beat input information aaaa: Similar to Shell read-p instructions
Name
' AAAA '
Name = input (' Please enter your name: ') defines the variable equivalent to the read-p shell rule
Print (' Hello, ', name)
· Data types are divided into (mutable and immutable) types:
Type mutable types can be viewed with the ID (a) for the unique identifier of the variable (the invariant is the variable type, the identifier transformation, the immutable type)
Immutable types include: (int,string, tuple) integers, strings, ganso
variable types include: (List,dict (Dictionary) ) list, dictionary
· Assignment of variables Everything is a reference, and why dynamic and dynamic types are no longer dynamic
· Multiple assignment variables, a,b,c = "1", "2", "3"; Print A,b,c The variables printed out are
· Delete Variable del A; multiple delete variable del a,b,c
· What exactly is the cognitive ASCII Unicode UTF8: byte code
Len can query how many characters are in a variable: use Len (a)
Convert ASCII bytecode to utf-8: a = "hahaha", G = A.decode (' Utf-8 '), then the Len (g) will show 3 bytecode.
The Chinese character code can also be defined as: a = "haha". Decode (' Utf-8 '); Len (a) will output 2 bytes.
· Escape characters:
A = u "haha" This u represents Unicode characters
>>> print R ' \ n '
\ n
>>> print ' 1\n1 '
1
1
· >>> a = "ABCDE"
>>> Print A[0]-----means printing out the first character in a variable string
>>> Len[a]-----can also see how many strings he has.
>>> A[5-1]-----is the 5th character of the query, and a character query that starts at 0 4 means the 5th character.
' E '--------printed results can also be printed with A[len (a)-1] "e" character, preferably a[-1]---print out the last character
· Use of a string template, placeholder usage
%s---placeholder string placeholder
%d---placeholder digital stand-up characters
>>> print "My name is%s xue"% "jian"
My name is Jian Xue
>>> print "My name is%s xue%s" percent ("Sunjianxue", "boy")----This is a multiple change
My name is Sunjian xue Boy
· A graceful way to string concatenation:
>>> a = "12323"
>>> B = "abc"
>>> C = "123"
>>> "". Join ([a,b,c])-----Output stitching, enter any word Fu Qi in "" as the concatenation complete after the delimiter.
' 12323abc123 '
>>> ",". Join ([a,b,c])------output using stitching characters, output results
' 12323,abc,123 '
· Read-Write text came: W write, R read, a append continue to add in the tail line
>>> d = open (' A.txt ', ' W ')----opens a file to write W
>>> d.write (' Hi.\nsecond hi. ') )----Write data to the file
>>> D.close ()-----to close the file after the operation is completed
>>> d = open (' A.txt ', ' r ')--------open opens a file for reading
>>> print d.readline ()-----Each output will be printed one line at a time, the output of a few cursors will go to the end of the last output line edge, if you want to show it all also need to restore to the original cursor
>>> d.seek (0)--------will be in the initial cursor
>>> print D.read (----------) indicates output 1000 characters
· mutable types and immutable types: (integers, Ganso, strings, immutable types), (lists, dictionaries, mutable types)
> >> a = [1,2,3,4]--------------mutable type
>>> Print a
1,2,3,4
>>> A[0] = 2
>>> Print a
2,2,3,4--------------mutable type
>>> B = "1,2,3,4"--------immutable type
>>> PINRT b
1,2,3,4
>>> a[0] = 2------------immutable type, so the change is unsuccessful error
· Py in-file editing
#coding =utf-8
D = "Chinese". Decode (' Utf-8 ')
Print Len (d)
The result of executing the script will be 2, and it will not be 2 characters if you do not convert Chinese characters.
This article is from the "Sno" blog, make sure to keep this source http://snlinux.blog.51cto.com/9114162/1737282
Python Beginner Doodle