Python lesson two, operators and basic data types

Source: Internet
Author: User

the python operator 1. Arithmetic operation:

2. Comparison operation:

3. Assignment Operation:

4. Logical Operation:

5. Member Arithmetic:

Basic data types for Python 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~9223372036854775807 2. Boolean valueTrue or False 1 or 0 3. String
"Hello World"
String Common functions:
    • Remove blank strip (self, Chars=none)
    • Split Partition (self, SEP)
    • Length __len__ (self)
    • Index []
    • Slice [:]
4. ListTo create a list:
123 name_list =[‘alex‘‘seven‘‘eric‘]name_list = list([‘alex‘‘seven‘‘eric‘])

Basic operation:

    • Index []
    • Slice [:]
    • Append Append (self, p_object)
    • Delete Remove (self, value)
    • Length Len
    • Loop for
    • Contains
5, GansoTo create a meta-ancestor:
123 ages =(1122334455)ages =tuple((1122334455))
Basic operation:
    • Index []
    • Slice [:]
    • Loop for
    • Length Len
    • Contains
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 [key]
    • Added [Key1]=value
    • Delete Clear
    • Key, value, key-value pair Keys,values,viewitems
    • Loop default Loop key
    • Length Len
PS: 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]  

Python lesson two, operators and basic data types

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.