The Heart of The Machine, by Laurent Pointal, siyuan, Liu Xiaokun.

Today’s Python 3 Cheat Sheet was summarized by Laurent Pointal, an engineer at the French Mechanical Engineering and Information Technology Laboratory (LIMSI) at the National Centre for Scientific Research (CNRS) in France. This simple Cheat Sheet focuses on the sections of the language necessary to start with algorithms/programming and provides the general information students need to get started. Note: It does not involve object-oriented programming.

The Python 3 Cheat Sheet consists of two pages divided into block diagrams covering basic Python data structures, mathematical operations, conditional and loop statements, file reading and writing, and outlier handling. In each block diagram, the upper right corner is the name of the type, blue and red fonts are the keywords included in the type, green fonts are examples, and black italics provide more detailed information.

  • Perso.limsi.fr /pointal/_me…

  • The address of the project: perso. Limsi. Fr/pointal/pyt…

Python3 basic data types and data structure types:

Data types: integer (int), float (bool), string (STR), binary byte sequence (including binary, octal, hexadecimal, bytes), and so on.

Data structure types contain ordered sequences and key-value containers. Ordered sequences include lists, tuples and strings, among which the important difference between lists and tuples is that the former is mutable while the latter is immutable. Lists are mainly used to store isomorphic data, while tuples are mainly used to store heterogeneous data. Key-value containers have no pre-set order and can be used to quickly find values by accessing keys, including dictionaries, collections, and so on.

Identifiers: Names used to represent variables, functions, modules, classes, etc. Do not use keywords in Python3. Python3 identifiers are case sensitive. Examples of permitted and disallowed identifiers are listed in the block diagram.

Variable assignment: Assignment refers to assigning a specific value to a variable. The left side of the equal sign is the name of the variable and the right side is the value. If you have a variable on the right, you can view it as a function; You can assign the same value to more than one variable; Multiple values can be assigned to multiple variables; You can swap the values of two variables; Can be used to represent loop statements, etc.

Type conversion: To convert data from one data type to another, or from one data structure to another. An expression can be summarized as type(expression), where type is the target transformation type and expression is the data or data structure to be transformed. Alternatively, you can format the list with a more specific sentence pattern, or simultaneously convert the data type for each data in the list.

Sequence container index: Used to sort lists, tuples, strings, bytes. You can use a positive index or a negative index. Once an index is defined, it is easy to access and assign (variables) to the container’s data. Data access/assignment can be applied to a single or multiple data, and can specify intervals, order, or reverse order.

The rest of the first page also includes: Boolean logic, declarative module structure, module import operations, mathematics, conditional declaration statement structure, and exception case handling statements.



Loop statements are one of the most core statements in a programming language, as shown on page 2 below. There are mainly while loops and for loops in Python. Where the While loop requires a “loop condition” that, if true, continues iterating. For loop, we can apply the variable “var” to a block of code that needs to loop, and the “For” statement iteratively extracts it from seqence. Note that both loops also have control statements, namely the break command, which immediately jumps out of the loop body, and the continue statement, which skips the rest of the current loop and enters the next loop.

Note that the for loop requires iterable targets — lists, tuples, strings, and so on — in order to extract elements from them. Besides, for… The in range() statement can iterate over numeric values, such as increasing from 0 to 9. Also shown in the figure above are the print() and input() functions, where the print() function prints strings, variables, and expressions.

Python provides a wide range of embedded operations, including operations on numeric variables and operations on various data structures. Operations on lists, dictionaries, collections, and general data structures are shown below, and string or tuple operations continue. For example, in general data structure operations, the len() function is probably the most common method to count the number of elements in different data structures. For example, if the output of all neurons is stored in a list, we can count the number of neurons using Len () and access the different neurons in turn using a for loop.

The list, dictionary, and collection operations that follow are all very important and are common in machine learning and programming in general. For example, in a list operation, the append() method adds a new element to the end of the list, extend() adds another sequence to the end of the list, and pop() removes an element from the list (the default last element) and returns the value of that element. There are many other ways to list data structures, including removing remove(), sorting sort(), and counting count().

In addition to lists, dictionaries are another important data structure and are likely to be used if we need to iteratively name parameters at different levels of the neural network. With dictionaries, we can use numeric, character, or other types of indexes. Each key=>value pair of the dictionary is separated by a colon (:), each pair is separated by a comma (,), and the entire dictionary is enclosed in curly braces ({}).

Dictionaries also have a number of methods, such as the clear() method to delete all elements in a dictionary, the items() method to return traversable tuples of (key, value) in a list, and the Update (d2) method to update dictionary D2’s key/value pairs into D, as shown above.

The most important thing in the following memo is the definition and invocation of functions, which are a core module in most programming languages. Functions are very simple to define and call, and this table only shows the basic concepts. Furthermore, this memo does not introduce object-oriented programming methods such as classes and instances.

Finally, file reading and writing, string manipulation and string formatting. Pandas is a library for reading and writing data. Libraries like Pandas are used to read and write data. During file processing, the open() method opens a file and returns the file object, raising OSError if the file cannot be opened. After opening a file and performing some operations, we generally need to write a string to the file using the write() method. Each time we open a file and finish reading or writing, we must use close() to close the file.



Finally, the full two-page Pyhon 3 memo is shown below, and if you need a clearer PDF, you can click “Read the Original.”