Underlying data type 1, number
int: (integer)
2. Boolean valueTrue or False 1 or 0#
None,"", (), [], {}, 0 ===> are False
3. String
"Hello World"
String Common methods:
. Capitalize () #首字母大写
# to center a string by adding a padding character (by default, a space) on both sides
. Find ()#find a substring, cannot find reverse back -1
. Join ()#This is important to stitch each element of a string to a specified delimiter
. Lower ()#returns a lowercase version
. replace ()#Replace the specified substring (old,new)
. Split ()#very important to split the string into sequences
. Strip ()#default to remove the beginning and end of whitespace, or to remove the specified string
. StartsWith ()#decide whether to start with xxx
. Format ()#string Formatting
F"{},{}" #3.6 Latest String format notation
4. ListCreate List: Name_list = ["GSD", "ASF"]
List Common methods
. Append ()#appends an object to the end of the list. Clear ()#Clear List. Copy ()#Shallow Copy list. Count ()#calculates the number of occurrences of a specified element in a list. Extend ()#Expand the meta-list, iterate through each element and add it to the list. Index ()#finds the index of the first occurrence of the specified value. Insert ()#insert an object into the list. Pop ()#the last element is deleted by default and the deleted value is returned. Remove ()#Delete specified value. Reverse ()#the elements in the list are reversed. Sort ()#default from small to large sort,. sort (reverse = True) sort from large to small
5, GansoFocus •: The first-level elements of a tuple cannot be modified, cannot be added and deletedCreate meta-ancestor: ages = (1,2,3,4,5)
Tuples have only two methods:
# gets the number of occurrences of the specified element # Find
6, Dictionary (is unordered)
Create Dictionary dict = {k:v,k:v} #键值对关系
Dictionary Common Methods
. Clear ()#Delete all dictionary entries. Copy ()#shallow copy a new dictionary{}.formkeys (['name',' Age'],"VV")#. Formkeys creates a new dictionary that contains the specified key, and the default value for each key is none. Do not want to use default values to provide specific values. Get ()#find the keys in the dictionary without returning none. Items ()#Returns a list that contains all the subkey items, each of which is in (k,v) Form. Keys ()#returns the keys in the dictionary. VALUES ()#returns the value in the dictionary. Pop ()#gets the value associated with the specified key and removes the key-value pair. Popitem ()#randomly bounces back a dictionary entry and deletes. SetDefault ()#set a value that already exists, does not set, gets the value corresponding to the current key, does not exist, adds the specified key value pair in the dictionary. Update ()#Update updates Another dictionary with an item in one dictionary, replacing it if the current dictionary contains an item of the same key
2.python Basic data types