Python development "full stack-day-iv": python basic data type

Source: Internet
Author: User

Operator 1. Arithmetic operation:

2. Comparison operation:

3. Assignment operation:

4. Logical Operation:

5. Member Arithmetic:

Basic data types 1. 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~9223372036854775807int 2. Boolean valueTrue or False 1 or 0 3. String
"hello world"
String Common Functions:
    • Remove whitespace
    • Segmentation
    • Length
    • Index
    • Slice
Str 4. ListTo create a list:
123 name_list =[‘alex‘‘seven‘‘eric‘]name_list = list([‘alex‘‘seven‘‘eric‘])

Basic Operation:

    • Index
    • Slice
    • Additional
    • Delete
    • Length
    • Slice
    • Cycle
    • Contains
List 5, GansoTo create a meta-ancestor:
123 ages =(1122334455)ages =tuple((1122334455))
Basic Operation:
    • Index
    • Slice
    • Cycle
    • Length
    • Contains
Lass tuple (object): "" "tuple (), empty tuple tuple (iterable), tuple initialized from iterable ' s items    If The argument is a tuple, the return value is the same object. "" "def Count (self, value): # Real Signature unknown;     Restored from __doc__ "" "t.count (value)--return Number of occurrences of value" "" return 0 def index (self, value, start=none, stop=none): # Real Signature unknown;        Restored from __doc__ "" "t.index (value, [start, [stop]), integer-return First Index of Value.        Raises valueerror if the value is not present. "" "return 0 def __add__ (self, y): # Real Signature unknown; Restored from __doc__ "" "x.__add__ (y) <==> x+y" "" pass def __contains__ (self, y): # real Signatur E unknown; Restored from __doc__ "" "x.__contains__ (y) <==> y in x" "" pass def __eq__ (self, y): # Real Signat Ure unknown; Restored from __doc__ """ x.__eq__ (y) <==> x==y "" "pass def __getattribute__ (self, name): # Real Signature unknown;  Restored from __doc__ "" "x.__getattribute__ (' name ') <==> x.name" "" pass def __getitem__ (self, y): # Real Signature unknown; Restored from __doc__ "" "x.__getitem__ (y) <==> x[y]" "" pass def __getnewargs__ (self, *args, **kwa Rgs): # Real Signature Unknown pass def __getslice__ (self, i, j): # Real Signature unknown;  Restored from __doc__ "" "x.__getslice__ (i, j) <==> x[i:j] use of        Negative indices is not supported. "" "pass def __ge__ (self, y): # Real Signature unknown; Restored from __doc__ "" "x.__ge__ (y) <==> x>=y" "" pass def __gt__ (self, y): # Real Signature U nknown; Restored from __doc__ "" "x.__gt__ (y) <==> x>y" "" pass def __hash__ (self): # Real Signature UNK nown;       Restored from __doc__ "" "x.__hash__ () <==> Hash (x)" "" pass def __init__ (self, seq= ()): # Known special case of tuple.__init__                "" "tuple (), Empty tuple tuple (iterable), tuple initialized from iterable ' s items        If The argument is a tuple, the return value is the same object. # (copied from class Doc) "" "pass def __iter__ (self): # Real Signature unknown; Restored from __doc__ "" "x.__iter__ () <==> iter (x)" "" pass def __len__ (self): # real Signature UN known; Restored from __doc__ "" "x.__len__ () <==> len (x)" "" pass def __le__ (self, y): # Real Signature UN known; Restored from __doc__ "" "x.__le__ (y) <==> x<=y" "" pass def __lt__ (self, y): # Real Signature U nknown; Restored from __doc__ "" "x.__lt__ (y) <==> x<y" "" pass def __mul__ (self, n): # Real Signature U nknown; Restored from __doc__ "" "x.__mul__ (n) <==> x*n"" "pass @staticmethod # known case of __new__ def __new__ (S, *more): # Real Signature unknown; Restored from __doc__ "" "t.__new__ (S, ...) A new object with type S, a subtype of T "" "pass def __ne__ (self, y): # Real Signature unknown; Restored from __doc__ "" "x.__ne__ (y) <==> x!=y" "" pass def __repr__ (self): # Real Signature Unkno Wn Restored from __doc__ "" "x.__repr__ () <==> repr (x)" "" pass def __rmul__ (self, n): # real Signatur E unknown; Restored from __doc__ "" "x.__rmul__ (n) <==> n*x" "" pass def __sizeof__ (self): # real Signature UN known; Restored from __doc__ "" "t.__sizeof__ ()--size of T in memory, in bytes" "" Pass
6. Dictionary (unordered)To create a dictionary:
123 person  =  < Code class= "python plain" >{ "mr.wu" ' age ' 18 or person  =  dict "mr.wu" 18

Common Operations:

    • Index
    • New
    • Delete
    • key, value, Key-value Pairs
    • Cycle
    • Length
DictPS: loops, Range,continue and break other 1. For loopThe user iterates through the contents of an object in order, ps:break, continue
123 li =[11,22,33,44]for item in li:    printitem
2, enumrateAdd an ordinal to an object that can be iterated
123 li =[11,22,33]for k,v inenumerate(li, 1):    print(k,v)
3. Range and xrangeSpecify a range to generate the specified number
12345678 printrange(110)# 结果:[1, 2, 3, 4, 5, 6, 7, 8, 9]printrange(1102)# 结果:[1, 3, 5, 7, 9]printrange(300-2)# 结果:[30, 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
123456 goods =[    {"name""电脑""price"1999},    {"name""鼠标""price"10},    {"name""游艇""price"20},    {"name""美女""price"998},]

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

12345678910111213 dic ={    "河北": {        "石家庄": ["鹿泉""藁城""元氏"],        "邯郸": ["永年""涉县""磁县"],    }    "河南": {        ...    }    "山西": {        ...    }}

Python development "full stack-day-iv": 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.