Notes (doing things in Python)--variables (numbers, strings)

Source: Internet
Author: User
Tags character classes repetition square root

  1. Python is a dynamic type and can be viewed with type ().
  2. Python object (object is an instantiation of a class, three main concepts encapsulation, inheritance, polymorphism);
  3. : Divide the symbol;
  4. Decimal type: High-precision numeric type, but not high efficiency;
  5. Common functions for numeric types: Import Math
  6. math.pi:π
  7. MATH.SQRT (80): Open square root
  8. MATH.LOG10 (2**1000): Log base 10
  9. Math.pow (x, y): x y-square
  10. Math.factoria (x): factorial
  11. Common functions for numeric types: import random
  12. Random.random (): Generates a random number between 0 and 1
  13. Random.choice ([1,2,3,4]): Randomly select one in the list
  14. Random.randint (b): Randomly select an integer between A and B
  15. Random.uniform (b): Random number evenly distributed between A and B, floating-point numbers
  16. Random.gauss (MU,LAMDA): Random number of Gaussian distributions, mu mean, lamda variance
  17. NumPy: Generating arrays or matrices, random numbers of normal distributions, matrix operations, inversion, transpose;
  18. SCIPY: Fitting, linear interpolation, spline interpolation, integral, differential, non-linear equation, filter design;
  19. String: Slice, index (String[1],string[1:3],string[1:6:2] Three parameters are Start,end,step,)
  20. String method: Split slice, join connection
  21. String Common methods: (1) "+" is combined before and after, (2) "*" Repeating composition, (3) S.upper () All Thank you, (4) s.find (' Pa ') to find the character containing PA, (5) s.replace (' Python ', ' Java ') ' Python ' replaced with ' Java '; (6) Substitution of variables in "%s" output string in print
  22. String-re module: Import re
  23. Re.match (P,text): Start with the string text header to find p, only return a match object, no return none;
  24. Re.search (p,text): Find p from the entire string text, return only a match object, no return none;
  25. Re.findall (P,text): Returns multiple results in the form of a list;
  26. Re.split (P,text): Splits the string, separating it according to the P character;
  27. Re.sub (p,s,text): Find p to replace p to s;
  28. 11 metacharacters in Python: \ ^ $.  |  ? *  +  ()  []  {}
  29. 11 metacharacters-Special meaning: \ (escape character). (denotes all characters except carriage return)
  30. 11 metacharacters-Optional: | (or), [] (OR)
  31. 11 metacharacters-Repeat: * (character repeats 0 or infinitely), + (character repeats once or infinitely),? (0 to 1 characters), {} (repeat word count, first parameter minimum repetition count, second parameter max repetition), ^ in [] mean non, *? (),+? (as few as possible)
  32. 11 Metacharacters-6 character classes: \d (0-9), \d, \s (\t\n\r\f\v), \s, \w (a-za-z_), \w (uppercase corresponding to the small W's non)
  33. 11 metacharacters-4 position classes: \b (boundary of word), \b (non-small B), \a (input start), \z (input end), (^ start, $ end)
  34. 11 metacharacters-Group: ()
  35. Re.findall (R ' ^c. ', text): Search from scratch for character ' C '? ' ... ' Two non-carriage return characters;
  36. Re.findall (R ' ... R $ ', text): Search from the end to ' ... ' Two non-return characters? character ' R ';
  37. Compilation options: I, L, M, S, U, X

Notes (doing things in Python)--variables (numbers, strings)

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.