"Book Notes", "Basic Python Tutorial" chapter I Basic knowledge

Source: Internet
Author: User
Tags integer division pow square root cmath

Chapter I basic knowledge
  1. achieve two-digit integer division: Use the command switch-qnew (? ); use a double slash.

  2. From The future Import Division performs normal division as the calculator.

  3. Exponentiation Operator: 2 * * 3 (8), with function instead of POW (2,3), built-in function

  4. Long integer type: At the end of the number plus L. eg:10000000000000l

  5. Get user input

    Input ("hint message:") eg:x = Input ("x:"). The input is a valid Python expression
    Raw_input ("hint message:"), put the user input as raw data into the string.

  6. Built-in function, Standard function--POW, ABS, round: Rounding the floating-point number to the nearest integer value.

  7. module, you need to import it into the Python extension feature with import.

    Eg:import math can be used Math.floor (32.9) #向下取整 32.0, ceil () rounding up
    Use INT () to cast to an integral type. Int (Math.floor (32.9)) # 32
    Use the From math import sqrt to use functions directly, without requiring the module name as a prefix.
    The function can be referenced by a variable, Eg:foo = math.sqrt foo (4) is the same as MATH.SQRT (4), the square root is computed, and the result is 2.0
    SQRT (-4) error, cannot process imaginary numbers (end with j), requires import Cmath, uses Cmath.sqrt (-4)

  8. The program automatically ends, you can add Raw_input ("Press") at the end of the code

  9. Concatenation of strings, "hello." + "World"

    string printing, str ("Hello,world") #转换为用户看到的字符串 Hello,world
    Repr ("Hello,world") #以合法的python表达式形式表示 ' Hello,world '
    This conversion is useful when printing includes a number variable.

  10. The long string "" or "' does not need to be escaped with a backslash.
    Note: The normal character spans the line: the last character in a row is a backslash, then "\" is the newline escape character

  11. The original string begins with "R", which avoids the use of escape characters. Eg:print r "C:\nowhere"

  12. A Unicode string, stored as a 16-bit Unicode character, and normally stored in 8-bit ASCII code.

"Book Notes", "Basic Python Tutorial" chapter I Basic knowledge

Related Article

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.