PYTHON-DAY03 (Record)

Source: Internet
Author: User

Strange things that you have encountered in practice

The rawinput in python2.7 or input is the string type.

The Append method used in list Ganso and other types has no return value, so once we assign a value, we get an error, the Update method does not have a return value, and the global variable is reused in the function, we'd better use the method of function parameter.

Print (" -5%s-10%s-10%s"% (a,b,c)) # #格式化输出, each character occupies 5,10,10 position, the% is preceded by a space, do not comma

Modifying global variables in functions requires using the Global keyword

Determine whether integers are judged by using the IsDigit method

String processing

S.find (Substring, [start [,end]])   #可指范围查找子串, returns the index value, otherwise returns -1   S.rfind (Substring,[start  [,end]])   #反向查找    S.index (Substring,[start [,end])   #同find, just can't find ValueError exception    S.rindex (Substring,[start [,end]]) #同上反向查找    s.count (Substring,[start [,end])   #返回找到子串的个数       s.lowercase ()    s.capitalize ()         #首字母大写    s.lower ()             #转小写    s.upper ()             #转大写    S.swapcase ()          #大小写互换       s.split (str,  '   ')     #将string转list,    s.join (list,  '   ') with space    #       A list to a string with a space to concatenate the built-in functions for processing strings    len (str)                   #串长度    cmp ("My friend",  str)     #字符串比较. The first big one, returning 1   max (' abcxyz ')            # Look for the largest character in the string    min (' abcxyz ')            # Find the smallest character in a string   List List Method    L.append (Var)       #追加元素    l.insert (index,var)    L.pop (Var)         #返回最后一个元素, and remove    L.remove (Var) from List       #删除第一次出现的该元素    L.count (Var)       #该元素在列表中出现的个数    L.index (Var)        #该元素的位置, none throw exception     L.extend (list)     # Append list, merge list to L    l.sort ()            #排序    L.reverse ()        #倒序   ··a[1:]          #片段操作符 for sub-list extraction   ·[1,2]+[3,4]   #为 [1,2,3,4]. Same extend ()   ·[2]*4         #为 [2,2,2,2]   del l [1]       #删除指定下标的元素   ·del L[1:3]    #删除指定下标范围的元素   Copy of   list    l1 = l         #L1为L的别名, in C is the same pointer address, the L1 operation is the operation of the L l1 = l[:]      #生成L的一个COPY   Ganso tuple: tuples (i.e., constant arrays)   ·tuple =  (' A ',  ' B ',  ' C ',  ' d ',   ' e ')    can use the list  [],: the operator extracts the element. Is that you cannot modify elements directly. Dictionary d.get (key, 0)         #同dict [key], more than one does not return the default value, 0. [] No exception thrown    D.has_key (key)        #有该键返回TRUE, otherwise false   D.keys ()                #返回字典键的列表    d.values ()            #以列表的形式返回字典中的值, the list of return values can contain duplicate elements    D.items (             #将所有的字典项以列表方式返回, each of these lists comes from (the key, the value), But the items are returned with no special order                d.update (DICT2)       #增加合并字典    d.popitem ()            #得到一个pair and remove it from the dictionary. Empty then throw exception    D.clear ()               #清空字典, same as Del  dict   d.copy ()               # Copy dictionary    d.cmp (dict1,dict2)    #比较字典, (priority is the number of elements, key size, key value size)   ·                      #第一个大返回1, small return-1, same as return 0  Replication of                  dictionary   ·dict1 = dict         #别名    dict2= Dict.copy ()     #克隆, another copy. The list and dictionary compare dict:– Find and insert very quickly, do not increase with the increase of key,-need to occupy a lot of memory, memory waste. –key Immutable – Default unordered list:– the time to find and insert increases as the element increases; – small footprint and little wasted memory. – Search by Subscript – ordered Set Set

Characteristics:

• unordered • Elements are not duplicated

Function:

• Relationship Testing • de-weight

A = set ([1,2,3,4])

b = Set ([3,4,5,6])

A & B #求交集 a.intersection (b)

A | b #求并集 A.union (b)

A–b # Finding the difference set A.difference (b)

A ^ b #求对称差集 a.symmetric_difference (b)

A.issubset (b) #a is a subset of B

A.issuperset (b) # A whether it contains B

PYTHON-DAY03 (Record)

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.