Tag: Row tells the preparation code comma result time assignment statement Pytho
Recently to go back to school to do the completion of the set, ready to do a related algorithm, I heard that Python operations better, specifically to learn.
Let's start with the basics .......... ...........
D1
1. Print prints each string sequentially, encounters a comma "," and outputs a space, so the output string is spelled like this:
1 Print ' The quick brown Fox ' ' jumps over ' ' The lazy dog ' 2 3 The quick brown fox jumps over the the lazy dog
1 print '+ + =', + + output Result: 100 + 200 = 30 0 (where, as a connection and + as an operation " as a string)
2. Python comments begin with the #
following text until the end of the line is counted as a comment
3. In Python, the equals sign =
is an assignment statement that can assign arbitrary data types to variables, the same variable can be repeatedly assigned, and can be different types of variables (looks more flexible than Java ...). But I think it's a little dangerous to use it badly.
4. Python also has an escape character, \ n is a carriage return, \ ' or \ ' is a quotation mark.
5. We can prefix the string to r
indicate that it is a raw string, and that the characters inside it do not need to be escaped. However r‘...‘
, the notation cannot represent multiple lines of string, nor can it represent ‘
"
a string containing and
If you want to represent multiple lines of string, you can use a ‘‘‘...‘‘‘
representation (similar to <blockquote>?). ):
"Line 1Line 2Line 3"
The above string is represented in exactly the same way as the following:
' Line 1\nline 2\nline 3 '
It can also be added in front of a multiline string r
, turning the multiline string into a raw string.
6. Because Python was born earlier than the Unicode standard, the earliest Python only supported ASCII encoding. Python later added support for Unicode, with a Unicode-represented string expressed in U ' ... '. Note: Without u, Chinese will not display properly.
A Unicode string u
is no different than a normal string, except for one more. If the Chinese string encounters unicodedecodeerror in a Python environment, this is because there is a problem with the format saved by the. py file. You can add comments on the first line:
#-*-Coding:utf-8-*-
The purpose is to tell the Python interpreter to read the source code with UTF-8 encoding. Then save as UTF-8 format. (This is two kinds of coding, can't put together to say)
7. With operation and, or operation or, not operation not. This is a bit like a short-circuit or short-circuit or short-circuit, returning the value before the short circuit. For example True and ' Hello World ' #返回True, if changed to False, return Hello World
8. Python's list contents are ordered and can be added and deleted at any time. The type can vary between data.
9.
Python, I've been learning t^t from scratch.