First, the Python Expression Foundation

Source: Internet
Author: User

Python can perform simple calculator functions: such as >>2+2 ==> 4,1/2==>0.5 or write 1/2.0==>0.5 (take float) 1//2 ==>0 ("//" will force rounding) -3**4 ==>- 81 (Power function operation level is higher than the first operation, similar to ==>-(3**4)), if you want to achieve the result is positive write: (-3) **4 can also be written as function pow (3,4) abs ( -1) ==>1 (ABS rounding) round (0.6) ==> 1 (Round rounding) Reference module: Import math (preferably with this) and then call Math.floor (12.7) ==>12 (rounding down) from math import sqrt (so that the reference module is not prefixed) for example: sqrt ( ==>4.0 of course, you can also use variables to kill methods such as: PF = MATH.SQRTPF (4) ==>2.0math.sqrt () can only handle floating point numbers, the remaining imaginary numbers (and the sum of the real and imaginary numbers) with cmath.sqrt (-16) = =>4jpython can handle large integers but need to add l to the end of the CountFor example: 1000000000000000000000000L variable names can be in letters, underscores (_) numbersbut you can't start with numbers .int (x [, Base]) converts x to an integer long (x [, Base]) converts x to a long integer, float (x) converts x to a floating-point number complex (R             EAL [, Imag]) creates a complex number str (x) to convert an object x to a string repr (x) to convert an object x to an expression string eval (str) Used to calculate a valid in stringPythonExpression and returns an object tuple (s) to convert the sequence s to a tuple list (s) to convert the sequence s into a listing Chr (x) will be a                 Converts an integer to a character unichr (x) converts an integer to a Unicode character, Ord (x) converts a character to its integer value, Hex (x) Converts an integer to a hexadecimal string Oct (x) converts an integer to an octal stringThere are two types of running code:1, >>> return immediately execute 2, plain text code and can be divided into two modes 1) Open the CMD input. The absolute path of PY 2) directly inside the IDE CTRL+F5The first python runs the program code as follows:Name = input ("What is your name?") #为变量name赋值print ("Hello" +name+ "!") #打印input ("press<enter>") #避免窗口闪退转义符 ("\") Example: "\" hello!\ "she said" ==> ' "hello!" she said ' "\ n" is a newline character, but sometimes I don't want him to escape in use for example: print ("C:\nwhere") ==>c:where now if we want ' C : \nwhere ' has two methods to implement 1, use ' \ ' escape characters such as print ("C:\\nwhere") ==>c:\nwhere2, take advantage of original characters such as: print (r "C:\nwhere") ==>c:\ Nwhere #原始字符最后一个字符不能为 ' \ ', otherwise python will not be able to recognize whether the string should end if you need to add ' \ ' after the original field to write print (r "C:\nwhere" "\") ==>c:\nwhere\ Continue learning data Structures tomorrow

First, the Python Expression Foundation

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.