Python

python.org 
How do I use Python?
Python and MySQL
Python Library Reference
CGI scripting and MySQL
PythonDEVcenter
Marc's Python Pages 
Python Resources 
Learning Python 
Programming Python 
DevSHED -- Python 
python classes 




Object TypeExample Constants/Usage
Numbers3.1415,1234,99l,3+4j
Strings'spam',"guido's"
Lists[1,[2, 'three'],4]
Disctionaries{'food':'spam','taste':'yum'}
Tuples(1,'spam',4,'U')
Filestest=open('eggs','r').read()
Standard Numeric Types
ConstantInterpretation
1234, -24,0Normal integers (C longs)
999999999999LLong integers (unlimited size)
1.23,3.14e-10,4E210,4.0e+210Floating-point (C doubles)
0177,0x9ffOctal and hex constants
3+4j,3.0+4.0j,3JComplex number constants
Python Expression Operators
OperatorsDescription
x or y,
lambda args:expression
Logical or (y is evaluated only if x is false),
anonymous function
x and yLogical and (y is evaluated only if x is true)
not xLogical negation
<, <=, >, >=, ==, <>, !=,
is, is not,
in,not in
Comparison operators,
identity test
sequence membership
x | yBitwise or
x ^ yBitwise exclusive or
x & yBitwise and
x << y, x >> yShift x left or right by y bits
X + Y, X - YAddition/concatenation, subtraction
x * y, x / y, x % yMultiplication/repetition, division, remainder/format
-x, +x, ~xUnary negation, identity, bitwise compliment
x [i], x[i:j], x.y, x(...)Indexing, slicing, qualification, function calls
(...),[...],{...},`...`Tuple,list,dictionary,conversion to string
Strings
OperationInterpretation
s1 =' 'Empty string
s2= "spam's"Double quotes
block = '''..."""Triple-quoted blocks
s1 +s2,
s2* 3
Concatenate,
repeat
s2[i],
s2[i:j],
len(s2)
Index,
slice,
length
"a %s parrot" % 'dead'String formatting
for x in s2,
'm' in s2
Iteration,
membership
String Formatting Codes
%sString ( or any object's print format )
%cCharacter
%dDecimal ( int )
%iInteger
%uUnsigned ( int )
%oOctal integer
%xHex integer
%XHex integer ( uppercase )
floating-point codes produce alternative representations for floating-point numbers
%eFloating-point format 1
%EFloating-point format 2
%fFloating-point format 3
%gFloating-point format 4
%GFloating-point format 5
%%Literal %
String Backlash Characters
\newlineIgnored (a continuation)
\\Backlash ( keeps one \ )
\'Single quote ( keeps ' )
\"Double quote ( keeps " )
\aBell
\bBackspace
\eEscape ( usually )
\000Null ( doesn't end string )
\nNewline ( linefeed )
\vVertical tab
\tHorizontal tab
\rCarriage return
\fFormfeed
\0XXOctal value XX
\xXXHex value XX
\otherAny other char ( retained )
Lists
OperationInterpretation
L1 = {}An empty list
L2 = [ 0, 1, 2, 3 ]Four items: indexs 0.3
L3 = ['abc,['def', ,'ghi']]Nested sublist
L2[i], L3[i] [j]
L2[i:j],
len(L2)
Index,
slice,
length
L1 + L2,
L2 * 3
Concatenate,
repeat
for x in L2,
3 in L2
Iteration,
membership
L2.append(4),
L2.sort(),
L2.index(1),
L2.reverse()
Methods: grow,
sort,
search,
reverse, etc..
del L2[k],
L2[i:j]=[]
Shrinking
L2[i]= 1,
L2[i:j] = [4,5,6]
Index assignment,
slice assignment
range(4), xrange(0, 4)Make lists/tuples of integers
Common Dictionary Constants & Operations
OperationInterpretation
d1={}Empty dictionary
d2 = {'spam':2,'eggs':3}two-item dictionary
d3 = {'food':{'ham':1,'egg':2}}Nesting
d2['eggs'],d3['food']['ham']Indexing by key
d2.has_key('eggs')
d2.keys(),
d2.values()
Methods: mebership test,
keys list,
values list, etc...
len(d1)Length ( number stored entries )
d2[key]=new,
del d2[key]
Adding/changing,
deleting
Tuples
OperationInterpretation
Files
OperationInterpretation
Python Statements
StatementRoleExamples
Assignment Statement Forms
OperationInterpretation
Common Python Expression Statements
OperationInterpretation
Print Statement Forms
OperationInterpretation
Function-Related Statements
StatementExamples

No comments:

Post a Comment