Python Basic data type

Source: Internet
Author: User

One, operator1. Arithmetic operation:

2. Comparison operation:

3. Assignment Operation:

4. Logical Operation:

5. Member Arithmetic:

II. Basic data types1. Digital

int (integral type)

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~92233720368547758072. Boolean valueTrue or False 1 or 03. String
"Hello World"
string Common functions:
    • Remove whitespace
    • Segmentation
    • Length
    • Index
    • Slice
4. ListTo create a list:
Name_list = [' Alex ', ' Seven ', ' Eric '] or name_list = List ([' Alex ', ' Seven ', ' Eric '])

Basic operation:

    • Index
    • Slice
    • Additional
    • Delete
    • Length
    • Slice
    • Cycle
    • Contains
5, GansoTo create a meta-ancestor:
ages = (11, 22, 33, 44, 55) or ages = tuple ((11, 22, 33, 44, 55))
Basic operation:
    • Index
    • Slice
    • Cycle
    • Length
    • Contains
6. Dictionary (unordered)To create a dictionary:
person = {"Name": "Mr.wu", ' Age ': 18} or person = Dict ({"Name": "Mr.wu", ' Age ': 18})

Common operations:

    • Index
    • New
    • Delete
    • Key, value, key-value pairs
    • Cycle
    • Length
PS: Loops, range,continue and break other1. For LoopThe user iterates through the contents of an object in order, Ps:break, continue
Li = [11,22,33,44]for item in LI:    print item
2, EnumrateAdd an ordinal to an object that can be iterated
Li = [11,22,33]for k,v in Enumerate (Li, 1):    print (K,V)
3. Range and xrange (Python3 obsolete)Specify a range to generate the specified number
Print range (1, 10) # results: [1, 2, 3, 4, 5, 6, 7, 8, 9] Print range (1, 10, 2) # results: [1, 3, 5, 7, 9] Print range (30, 0,-2) # Result: [3 0, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
Exercises

First, the element classification

There is a collection of the following values [11,22,33,44,55,66,77,88,99,90 ...], saving all values greater than 66 to the first key in the dictionary, and saving the value less than 66 to the value of the second key.
That is: {' K1 ': All values greater than 66, ' K2 ': All values less than 66}

Second, findFinds the elements in the list, removes the spaces for each element, and finds all elements that begin with a or a and end with C. Li = ["Alec", "Aric", "Alex", "Tony", "Rain"] Tu = ("Alec", "Aric", "Alex", "Tony", "rain") dic = {' K1 ': "Alex", ' K2 ': ' Aric ', ' K3 ': ' Alex ', ' K4 ': ' Tony '}third, the output commodity list, the user enters the serial number, displays the user to select the productProduct Li = ["Mobile phone", "Computer", "mouse pad", ' yacht ')four, shopping cart

Functional Requirements:

    • Require users to enter total assets, for example: 2000
    • Display the list of items, let the user select the item according to the serial number, add the shopping cart
    • Purchase, if the total amount of goods is greater than the total assets, indicating that the account balance is insufficient, otherwise, the purchase succeeds.
    • Add: Can recharge, a product to remove the shopping cart
Goods = [    {"name": "Computer", "Price": 1999},    {"name": "Mouse", "Price": ten},    {"name": "Yacht", "Price": $},    {"Name ":" Beauty "," Price ": 998},]

V. User interaction, showing the choice of three-level linkage between provincial and municipal counties

DIC = {"    Hebei": {"        Shijiazhuang": ["Luquan", "Gaocheng", "Yuanshi"],        "Handan": ["Yongnian", "she County", "CI"],    }    "Henan": {        ...    }    " Shanxi ": {        ...    }}

Reference: http://www.cnblogs.com/wupeiqi/articles/5444685.html

Python Basic data type

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.