python study notes (1)

Python: The Dutch Uncle Turtle was founded by grandma at Christmas in 1989 (glue language)
Features: elegant, clear, and simple
Contrast between languages:
type, running speed, code amount,
C compiles to machine code very fast, very much
JAVA compiles to bytecode fast More
Python interpretation and execution is slower than
Python and other languages: Disadvantages: slow operation, Python source code cannot be encrypted

Basic data types: integer, floating point, string and boolean types, as well as the concept of variables and basic data operations

Under Python 2.7: / and // are both integer division (that is, two division symbols, the quotient retains the integer part) (if you want floating point division, the old use type conversion float(a)/b)
Under Python 3.x: / for floating point division (such as 1/2=0.5)
// for integer division (such as 1//2=0)
String: any text enclosed in '' or "", such as 'abc'
if in the string If it contains '', the string can be enclosed with "". If it contains " ", the string can be enclosed with ''.
If both are present, some special characters of the string need to be escaped (in its Insert \ in front of it to indicate that this is a common character (escape characters are not included in the content of the string)) such as: 'Bob said \"I\'m OK \".'
raw string: if the string contains many needs Escaped characters, you can add a prefix r in front of the string (indicating that this is a raw string), and the characters inside do not need to be escaped as
multi-line strings: '''
(content)
'''
boolean value : True False (pay attention to case)
null value: special value, represented by None (None cannot be understood as 0, because 0 is meaningful, and None is a special null value)

Print statement: For example: print 'hello, world' (print string)
The print statement can also keep up with multiple strings (knowledge points), separated by commas, and they can be connected into a string (when a comma is encountered during printing, it will print a space)
print can also print integers or the result of a calculation.
For example:
print 'The quick brown fox','jumps over','the lazy dog'
The quick brown fox jumps over the lazy dog
​​print 300
300
print 100+200
300
print 100<99
False
print 0xff==255
True

When writing code in an interactive mode environment >>> is the prompt of the python interpreter, do not add <<< yourself when writing in a text editor

A comment starts with #, and the text that follows is a comment until the end of the
line. Multi-line comments:
...
the content being commented to
...
Variables: Variables are represented by a variable name, (the variable name must be a combination of uppercase and lowercase English, numbers and underscores _ ,Do not start with a number)
In Python, = is an assignment statement, which can copy any data type to a variable, the same variable can be copied repeatedly, and can be different types of data
For example: a=123 #a is an integer
a='imooc ' #a is a string
, a language in which the type of the variable itself is not fixed is called a dynamic language (the variable type does not need to be declared when defining the variable), and the corresponding year is the static language. The
static language must specify the variable type when defining, if When the type does not match, an error will be reported (such as C/C++ language)
to understand the representation of variables in computer memory:
a='ABC'
1. Create a string of 'ABC'
in memory 2. Created in memory A variable named a and point it to 'ABC'
assigning a variable a to another variable b is actually pointing the variable b to the data pointed to by the variable a

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324847321&siteId=291194637