Python learning Footprint (3)

Source: Internet
Author: User
1. Some built-in functions:
Coerce converts two variables to the same type.
>>> Coerce (1, 2.2)
(1.0, 2.2000000000000002)

Filter, filter (function, list) (2.

Input () enter a number
>>> A = input ("Age :")
Age: 20
>>>
20

Open (), open the file, open (filename, Mode)
Pow (x, y), POW (2, 10) = 1024
Raw_input (prompt) input string
Reduce (fun, list)
>>> Import operator
>>> Reduce (operator. Add, [1, 23])
24

Range, xrange, and xrange will not cause insufficient memory.
Len () return Length
Max (1, 2, 3) = 3
Min (1, 2, 3) = 1
Setattr (object, name, value)
Getattr (object, name)
Hasattr (object, name)
Delattr (object, name)
Type (object), type ('') = <type 'str'>
Dir () lists available syntaxes, such as: Import OS: Dir (OS)
Callable (object), whether it can be called

ABS ()
CMP (x, y), x> Y return 1, x = y return 0, x <Y, return-1
Round (Num, DEC), round (10.45, 1) = 10.5, DEC is the number of reserved decimal places.
Eval ('2*3 + 1') = 7
Exec: Execute the python statement,
>>> A = 'print "hello "'
>>> Exec
Hello
Execfile (File): Execute python in file

CHR (integer), CHR (65) = 'A ',
Ord ('A') = 65
Hex (), convert to hexadecimal. Hex (12) = 0xc

2. File Operations
Read (), read (nbytes). If there are digits, read the bytes of nbytes; otherwise, read all.
Readline () reads a row
Readlines () reads all rows and returns them as a list.
Write (), write the string.
Writelines (list), write multiple rows
The position where seek () redirects to the file. 0 indicates the beginning, 1 indicates the current, and 2 indicates the end.
Tell (), returns the current pointer.
Flush ()
Close ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.