Python full stack day 2 data type

Source: Internet
Author: User

One, module

SYS module OS module

Import SYS # print (Sys.path)   #打印环境变量 print(sys.argv)print(sys.argv[2])
View Code
Import OS # cmd_res = Os.system ("dir")   #执行命令  , does not save the result Cmd_res = Os.popen ("dir"). Read ()print("--", Cmd_res) os.mkdir (" New_dir ")
View Code

Two, what is PYC?

PYc is compiled by the py file after the binary file, the py file becomes PYc file, the speed of loading increased, and PYC is a cross-platform bytecode, is executed by Python virtual machine. PYC content, is related to Python version, the different version of the compiled PYc file is different, 2.5 compiled PYC files, 2.4 version of Python is not executable. PYC files can also be deserialized, and different versions of the compiled PYC files are different.

How to compile into a PYC file that can be run:

Python 2.7.1 (r271:86832, Nov, 18:30:46) [MSC v.1500 + bit (Intel)] on
Win32
Type "Help", "copyright", "credits" or "license" for more information.
>>> Import Py_compile
>>> py_compile.compile ("d:/test.py")
>>>

Batch compilation only needs to enter the corresponding directory name

You can now see that the PYc file was produced in the corresponding directory

The PYc file is a byte code that is used to save the build of a Python virtual machine . In the run of Python, if you encounter import, first look for the corresponding. pyc or. dll file in the set path. If you do not have these files, compile the corresponding pycodeobject and wear the. pyc file to write intermediate results.

Third, data type

The Python Number data type is used to store numeric values.

The data type is not allowed to change, which means that if you change the value of the Number data type, the memory space will be redistributed.

Python supports four different numeric types:

    • Integer (Int) -usually referred to as an integer or integral, is a positive or negative integer, with no decimal points.
    • long integers -an integer with an infinite size, and an integer that ends with an uppercase or lowercase L.
    • float (floating point real values) -floating-point types consist of integral and fractional parts, and floating-point types can also be represented using scientific notation (2.5e2 = 2.5 x2 = 250)
    • complex numbers ((complex numbers)) -complex numbers are made up of real and imaginary parts, and can be represented by a + BJ, or complex (A, a, b), where both the real and imaginary part of a complex number are floating-point types.
int long Floa T complex
ten 51924361L 0.0 3.14j
-0x19323l 15.20 45.j
-786 0122 L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32 .3+e18 . 876j
-0490 535633629843L -90. -.6545+0j
-0x260 -052318172735l -32.54e100 3e+26j
0x69 -4721885298529l 70.2-e12 4.53e-7j
    • Long integers can also use lowercase "l", but it is recommended that you use uppercase "L" to avoid confusion with the number "1". Python uses "L" to display the long integer type.
    • Python also supports complex numbers, which consist of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where the real and imaginary parts of a complex number are floating-point

2. Boolean value TRUE or False 1 or 03, string
"Hello World"

string concatenation of all evils: the string in Python is embodied in the C language as a character array, each time you create a string, you need to open a contiguous space in memory, and once you need to modify the string, you need to open up again, the evil + sign every occurrence will re-open a space within. String Formatted output
" Alex " Print "  " % name# output: I am Alex

The string is%s; integer%d; floating-point number%f

Python Number Type Conversion
Int(X[,Base ]) WillXConvert to an integer Long(X[,Base ]) WillXConvert to a long integer Float(X) WillXConvert to a floating-point numberComplex(Real[,Imag]) Create a complex numberStr(X) The objectXConvert to StringRepr(X) The objectXConvert to an expression string Eval(Str) Used to calculate a valid in stringPythonexpression, and returns an objectTuple(S) The sequenceSConvert to a single tupleList(S) The sequence s  Convert to a list  Chr (x )   convert an integer to a character  Unichr (x )   convert an integer to unicode  character  Ord (x   convert a character to its integer value  Hex (x Span class= "pun" >)   convert an integer to a hexadecimal string  Oct ( x )   convert an integer to an octal string 
Five, data arithmetic
Arithmetic operations (add, subtract, multiply and divide) (+,-, *,/)

Comparison operation

Ternary operations
L = [1,2,3,4,5]                     for in  L:                             If i < 5   else None     Print (res)                                                              
if Else value 2

If the condition is true: The result is a value of 1
If the condition is false: The result is a value of 2

Name ="Alex"This is an operation chain assignment that assigns a value to a variable: a= B = C =1Print(a)Print(b)Print(c) a,b,c= 1,3,5Print(a)Print(b)Print(c) A, B= 3,5Print(a)Print(b) a B=B,aPrint(a)Print(b) x= x +a is equal to x +=a
View Code

Python full stack day 2 data type

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.