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 Type | Example Constants/Usage | |
Numbers | 3.1415,1234,99l,3+4j | |
Strings | 'spam',"guido's" | |
Lists | [1,[2, 'three'],4] | |
Disctionaries | {'food':'spam','taste':'yum'} | |
Tuples | (1,'spam',4,'U') | |
Files | test=open('eggs','r').read() | |
Standard Numeric Types | ||
Constant | Interpretation | |
1234, -24,0 | Normal integers (C longs) | |
999999999999L | Long integers (unlimited size) | |
1.23,3.14e-10,4E210,4.0e+210 | Floating-point (C doubles) | |
0177,0x9ff | Octal and hex constants | |
3+4j,3.0+4.0j,3J | Complex number constants | |
Python Expression Operators | ||
Operators | Description | |
x or y, lambda args:expression | Logical or (y is evaluated only if x is false), anonymous function | |
x and y | Logical and (y is evaluated only if x is true) | |
not x | Logical negation | |
<, <=, >, >=, ==, <>, !=, is, is not, in,not in | Comparison operators, identity test sequence membership | |
x | y | Bitwise or | |
x ^ y | Bitwise exclusive or | |
x & y | Bitwise and | |
x << y, x >> y | Shift x left or right by y bits | |
X + Y, X - Y | Addition/concatenation, subtraction | |
x * y, x / y, x % y | Multiplication/repetition, division, remainder/format | |
-x, +x, ~x | Unary negation, identity, bitwise compliment | |
x [i], x[i:j], x.y, x(...) | Indexing, slicing, qualification, function calls | |
(...),[...],{...},`...` | Tuple,list,dictionary,conversion to string | |
Strings | ||
Operation | Interpretation | |
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 | ||
%s | String ( or any object's print format ) | |
%c | Character | |
%d | Decimal ( int ) | |
%i | Integer | |
%u | Unsigned ( int ) | |
%o | Octal integer | |
%x | Hex integer | |
%X | Hex integer ( uppercase ) | |
floating-point codes produce alternative representations for floating-point numbers | ||
%e | Floating-point format 1 | |
%E | Floating-point format 2 | |
%f | Floating-point format 3 | |
%g | Floating-point format 4 | |
%G | Floating-point format 5 | |
%% | Literal % | |
String Backlash Characters | ||
\newline | Ignored (a continuation) | |
\\ | Backlash ( keeps one \ ) | |
\' | Single quote ( keeps ' ) | |
\" | Double quote ( keeps " ) | |
\a | Bell | |
\b | Backspace | |
\e | Escape ( usually ) | |
\000 | Null ( doesn't end string ) | |
\n | Newline ( linefeed ) | |
\v | Vertical tab | |
\t | Horizontal tab | |
\r | Carriage return | |
\f | Formfeed | |
\0XX | Octal value XX | |
\xXX | Hex value XX | |
\other | Any other char ( retained ) | |
Lists | ||
Operation | Interpretation | |
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 | ||
Operation | Interpretation | |
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 | ||
Operation | Interpretation | |
Files | ||
Operation | Interpretation | |
Python Statements | ||
Statement | Role | Examples |
Assignment Statement Forms | ||
Operation | Interpretation | |
Common Python Expression Statements | ||
Operation | Interpretation | |
Print Statement Forms | ||
Operation | Interpretation | |
Function-Related Statements | ||
Statement | Examples |
No comments:
Post a Comment