Python 0 Basic Learning-Fundamentals 3-modules, data types and calculations

Source: Internet
Author: User
Tags bitwise bitwise operators logical operators

Module : Encapsulated function, also known as library

    • Standard library: No installation required, can be directly imported, such as: sys, OS. Note: The import library name is not the same as the current file name
    • Third party libraries: need to download the installation, in order to use

Example:

Import SYS Import OS Print # Print Environment Variables Print # prints the path of the current script, the absolute path is printed in Pycharm, and the relative path is printed in cmd # View all files in the current directory  Note: Execution can be output to the screen, but will not be stored res=os.system ("dir")  Print# printing results of 0

Attention:

    • Import the xx.py file, and when you execute the script, it will be executed directly xx.py
    • Files can be directly import under the same path
    • If you create a new path, you can place it in an environment variable; or place the file directly in the folder that the environment variable refers to

Data operations

Mathematical operators: +-*/* (Power)% (modulo, returns the remainder of the division; common for odd pages even)//(divisible, returns the integer part of the quotient)

Conditional operator: = = = = <> > < >= <=

Assignment operator: = = = = *=/=%= **=//=

Logical operators: And Or not (for example: not 1==1)

Member operators: in Not IN (for example: if 1 in [1, 2, 3, 4])

Identity operator: is isn't (for example: a=[1,2,3,4] If Type (a) is list:)

Bitwise operators: & (bitwise VS: A&B) | (bitwise OR) ^ (bitwise XOR, XOR: Difference is 1, otherwise 0) ~ (bitwise Reversed) << (shift left) >> (shift right)

Ternary operators:

A, B, C=1, 3, 5

D=a if a>b else C #如果a >b is true, then D is assigned a, otherwise D is assigned C

Python 0 Basic Learning-Fundamentals 3-modules, data types and calculations

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.