Data |
Example |
Digital |
1234,3.1415,3+4j |
String |
' Spam '. " Grace ' s " |
List |
[1,[2, ' three '],4] |
Dictionary |
{' food ': ' spam ', ' taste ': ' Yum '} |
Meta-group |
(1, ' spam ', +, ' AB ') |
File |
File = open (' Eggs ', ' r ') |
Collection |
Set (' abc '), {' A ', ' B ', ' C '} |
Other types |
None, type Boolean |
Digital
Number type:
- integers: integers with no fractional parts
- Floating-point number: Numbers with a decimal part behind it
- Other: decimal number with imaginary part, fixed precision, rational fraction with numerator and denominator, set
String
Single quote ' and double quotation mark ' to create a string
var1 = "Double quotation mark"
VAR2 = ' single quote '
List
The most common sequence in Python is the list object. A list is an ordered collection of positions related to an arbitrary type of object, with no fixed size. Similar to arrays in Java, but more powerful than arrays. The list can include integers, strings, floating-point numbers, and even lists. Example: L = [123, ' spam ', 12.34, [n/A]]
List = [element 1, Element 2, ...]
Dictionary
A dictionary in Python is a mapping (mapping), which is stored by key, and the key is mapped to a value. A dictionary is the only data structure in Python that has a type of mapping. As with lists, dictionaries are also variable and can be enlarged or reduced.
Dictionary = {Key 1: value 1, key 1: Value 2}
Meta-group
Tuples are like immutable lists, with immutability. Because of his immutability, tuples provide an integrity constraint that is often used to write larger programs.
Tuple = (element 1, Element 2)
File
The file object is the primary interface for external files on your computer in Python code. However, there is no specific common syntax for creating files in Python. To create a file object, you need to call the built-in open function as a string to give it an external file name and a string to handle the pattern.
File = open (' Data.txt ', ' W ')
Python's core data structure