- octal literals begin with 0,contain 0-7 - Hex literals begin with 0X,contain 0-9 and A-F • Floating point: 12.3 1E1 -1.54E-21 - type 'float' - e or E • Long integers: 10000000000000000000000000000000L - type 'long' - end with l or L - any magnitude,no overflow • Complex numbers: 1+2J 3-5j - type 'complex' - end with j or J
or """...""" - useful for large chunks of text • Can't be changed in Python!Immutable • Escape character: \ - \n,\t,\\,\',\"... Raw string: r or R - useful for regular expression - eg,path=r'F:\Develop\Python\code\basic.py'
to last:0,1,2... - last to first:-1,-2,-3... Index can be negative! • 6 built-in sequence - list,tuple,string,Unicode string,buffer,xrange Common sequence operation - indexing,sliceing,adding,multiplying,checking membership
maps to a value • Also called "mapping" or "hash table" • The key - must be an immutable object - usually be an integer or a string - occurs at most once in a dictionary • The value - may be any object - occurs many times in a dictionary
an object with 'next' method - method '__iter__' return an iterator itself - method 'next' return next value,else raise StopIteration - one value one time,low memory compared with list
function body follows;indented - can be placed basically anywhere - required:define the function before calling it Function features - use the documentation string;strongly encouraged - may return more than one value;tuple
When argument not given in a call,default value is used • If no default value,and not given when called:bombs • Use explicit names to override argument order
have to use the 'return' statement • If not,then same as a 'procedure' in other languages • Actually returns a value:'None' • 'None' is a special value built-in Python - meaing 'nothing' - useful in many contexts
of functions and classes • Easy to create:every Python source code is a module • Powerful:many standard library modules • Easy to extend:many third-part library modules available
are special • Some are created automatically during execution - __name__,__doc__,__file__,__builtins_ Use '__name__' to self-test in module - if executed as the main program,then value '__main__' - if executed as a module,then some other module name
structure will be;attributes - What they will be able to do;methods • Objects are instances of classes - An object is a container of data;attributes - An object has associated functions;methods • Classes are the basicis of OOP - abstract,encapsulation,inheritance,polymorphism
public,'__xxx' means private • The first argument of methods must be 'self' • Access attrs and methods by 'self.' in class • Special methods '__xxx__',automatically called - __init__,__del__,__repr__,__len__