1. Notepad can set-preferences-language-tab to spaces
2. Editor recommended Sublime
3. Data type:
3.1 If there are many characters in the string that need to be escaped, you need to add a lot \
, in order to simplify, Python also allows r‘‘
‘‘
the expression of the internal string default is not escaped;
3.2 If there is a lot of line wrapping inside the string, \n
writing in a row is not good to read, in order to simplify, Python allows ‘‘‘...‘‘‘
the format to express multiple lines of content;
3.3 with and OR or not
3.4 Null is a special value in Python, None
denoted by. None
cannot be understood as 0
, because 0
it is meaningful, and None
is a special null value.
In addition, Python provides a variety of data types such as lists, dictionaries, and also allows you to create custom data types;
3.5 in Python, an equal sign =
is an assignment statement that assigns any data type to a variable, the same variable can be repeatedly assigned, and can be a variable of different types--the characteristics of a dynamic language
In Python, constants are typically represented in all uppercase variable names: But constants are still variables, and Python has no mechanism to guarantee that they are not changed--using all uppercase variable names to represent constants is only a customary usage.
3.6 //
, called the floor, takes only the integer part of the result, rounding down
4. String & Encoding:
4.1 Unicode (computer memory usage)--utf-8 (Unicode compression type, hard disk, transport)--ascii (subset of Unicode\utf-8)
4.2 In the latest version of Python 3, the strings are encoded in Unicode;
For the encoding of a single character, Python provides an ord()
integer representation of the function to get the character, and the chr()
function converts the encoding to the corresponding character;
Because the Python string type is str
, in memory, in Unicode, one character corresponds to a number of bytes.
If you want to transfer on a network, or save to disk, you need to turn it str
into bytes bytes
.
Python bytes
uses b
a prefixed single or double quotation mark for data of type:x = b‘ABC‘
Be aware of the distinction ‘ABC‘
and the b‘ABC‘
former is str
that although the content is displayed in the same way as the former, bytes
each character occupies only one byte.
The pass-through method that is represented in Unicode str
encode()
can be encoded as a specifiedbytes----要把bytes
变为str
,就需要用decode()
方法
The 4.3 len()
function calculates the str
number of characters, and if bytes
so, the len()
function calculates the number of bytes:
4.4 Formatting
%d |
integers (formatted integers and floating-point numbers can also specify whether to fill 0 and integers with decimals) |
%f |
Floating point number |
%s |
String ( %s always works, it converts any data type to a string, which is used %% to represent one % ) |
%x |
hexadecimal integer |
[Go_on]2017-1-18 Python Basics