Python-based data types

Source: Internet
Author: User

List

Increase:

name = []name.append () Name.insert (index, Element) #元素

By deleting:

Name.pop (index), default lastname.remove (Element) del name[index]names.clear () #清空列表del names  Delete list

Change:

Name[index] = newvalue #新的值names. Extend (names2) #扩展names = names + names2 #扩展 #names2.reverse () #反转, Names2.sort () #排序, press as Order of CII Tables

Check:

Name.index (Element)  #返回index值name. Count (Element) Name[index] #返回对应的值name #返回整个列表

Collection
Linux = {"Alex", "SB", "AA"}python = {"Alex", "SB", "BB"}

Intersection:

Print (linux.intersection (python)) print (Linux & python)  

Subtraction

Print (linux.difference (python))  #差集, Linux has, Python does not have print (Python.difference (Linux)) #差集, Python has, Linux does not have print (Linux-python)

and set:

Print (linux.union (python)) print (Linux|python)

Inverse difference set, inverse and set:

Print (linux.symmetric_difference (python)) #对称, difference sets, printed on each other (linux ^ python) #对称, the difference between the print

Merge:

Linux.update (python)  #把Python合并到linux集合中

Increase:

Linux.add ("ALEX")

Delete:

Linux.discard ("Alex") #删除, the same as remove, but if the element does not exist will not error Linux.pop () # Randomly delete the Linux.remove (' Alex ') #删除, but if the element does not exist will be an error

Other:

Linux.difference_update (Python) is a subset of #求差集并赋值给Linux集合print (Linux.issubset (Python)) #, Linux has a few, and Python has print ( Linux.issuperset (Python) # superset, parent Set print (Linux.isdisjoint (python)) # If two subsets are not the same, then return True

String
name = "Alex eee Li" Print (Name.capitalize ()) #首字母大写print (Name.casefold ()) # Uppercase to lowercase if choice = = "Y" or choice = = "Y" Print (n Ame.center (()) #长度多少, not enough to fill-print (Name.count (' e ')) #统计字母出现的次数print (Name.count (' e ', 3,7) #统计3到7 There are several eprint ( Name.endswith ("Li")) # What's the end of name = "Alex\teee Li" Print (Name.expandtabs ()) #设置 \ t's length print (Name.find ("E")) print ( Name.find ("SDF", 3)) #返回找到的第一个值的索引, return-1 if not found
Formatted output
Print (' A1A '. Isalnum ()) #a-za-z 0-9print ("10.1". Isdecimal ()) #是不是一个正整数print (' AA '. Isalpha ()) #是不是字母print (' a '). Isidentifier ()) #identifier The keyword, is not a valid keyword, is not a valid variable name. Print (' A '. Islower ()) #是不是小写print (' a '. Isupper ()) #是不是大写print (' a '. isprintable ()) #是不是可打印print (". Isspace ()) # is not a blank print (' Today headline '. Istitle ()) #是不是英文标题li = [' Alex ', ' Jack ', ' Rain ']print (': '. Join (LI))   #把列表拼接成字符串print ( Name.ljust (+, '-')) #左对齐print (Name.rjust ()) #右对齐print (Name.lower ()) #大写变小写print (Name.lstrip ("Al")) # Remove left what print (Name.swapcase ()) #大小写互换name = "My name is {0}, I am {1} years old" in = "ABCDE" out= "[Email protected]#$%" trans_t able = Str.maketrans (in,out) print (Name.translate (trans_table))   #字符翻译print (name.replace (' name ', ' name ', 1)) # Replace print (Name.center (), '-') print (Name.count ("my")) name= "Luchuan Gao" Print (Name.casefold ())

Python-based data types

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.