Python's core data type (built-in)
Number: Int,long,float,complex (plural), bool (Boolean)
Character: Str,unicode
Listing: List
Dictionary: Dict
Tuples: Tuple
Files: File
Other types: Collection (set), Frozenset (frozen set), class type, None
Other file class Tools: Pipes (Pipeline), FIFOs (FIFO pipeline), sockets (socket)
Type conversions:
Built-in function to complete non-string conversion to character type
STR (): Similar to print output
Repr (): Indicates the exact value
Format (): Converting in a specific format
Digital conversions:
Int (): Convert to Integer
Float (): Convert to floating point
Convert to Integer type:
str2 = ' 45 '
Type (STR2)
Str
Transformation:
num3 = Int (str2)
Type (STR2)
Int
Print num3
45
List conversions
List (s): Convert string S to list
STR2 = "Hello World"
num3 = List (str2)
Print num3
Output:
[' H ', ' e ', ' l ', ' l ', ' o ', ' ', ' W ', ' o ', ' r ', ' L ', ' d ']
Tuple conversions
Tuple (s): Converts a string s to a tuple
STR2 = "Hello World"
NUM4 = tuple (str2)
Print Num4
Output:
(' H ', ' e ', ' l ', ' l ', ' o ', ' ', ' W ', ' o ', ' r ', ' L ', ' d ')
Collection conversions
Set (s): Converts the string s to a collection
STR2 = "Hello World"
NUM5 = Set (STR2)
Print NUM5
Output:
Set ([' ', ' e ', ' d ', ' H ', ' l ', ' o ', ' r ', ' W '])
Converting to a collection will place the same letters in the same order, and there are no specific sequences;
Dictionary conversions
Dict (d): Creating a Dictionary
D must be a tuple sequence of key-value pairs
Creates a dictionary based on the specified key value pair;
D1 = [(' A ', 1), (' B ', 2)]
NUM1 = dict (D1)
Print NUM1
Output:
{' A ': 1, ' B ': 2}
Marco-python-class notes 12-python Core data type and type display conversion