Python Learning notes (1)

Source: Internet
Author: User

Python: Dutch turtle uncle at 1989 Granny Christmas Creation (glue language)
Features: Elegant, clear, simple
The contrast between languages:
Type run Speed code amount
C compiled to machine code very fast very much
JAVA compiles to bytecode fast
Python explanation Execution Slow
Python vs. Other languages: Disadvantage: Slow running, Python source code cannot be encrypted

Basic data types: integers, floating-point numbers, String and Boolean types, and the concept of variables and basic data operations

Python 2.7:/and//Both are integer divisions (i.e. two division symbols, the quotient retains the integer portion) (if you want the floating-point division old use type to convert float (a)/b)
Python 3.x:/For floating-point division (e.g. 1/2=0.5)
For integer division (e.g. 1//2=0)
String: Any text enclosed in "or", such as ' ABC '
If the string contains "", the string can be enclosed in "", if it contains ", you can enclose the string.
If both are available, some special characters of the string need to be escaped (before it is inserted \ means that this is an ordinary character (the escape character is not counted into the contents of the string)) such as: ' Bob said \ ' i\ ' m OK \ ".
Raw string: If the string contains a lot of characters that need to be escaped, you can prefix the string with R (meaning it's a raw string), and the characters don't have to be escaped.
Multi-line string: ' '
Content
’’’
Boolean value: True False (note case)
Null: Special value, denoted by none (none is not understood as 0 because 0 is meaningful, and none is a special null value)

Print statement: For example: print ' Hello,world ' (printed string)
Print statements can also be followed by multiple strings (knowledge points), separated by commas, can be connected to a string (when printing a comma, will output a space)
Print can also be printed with integers or calculated results
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 a prompt for the Python interpreter, do not add it yourself when writing in a text editor <<<

Comments begin with #, followed by text that knows the end of the line is counted as comments
Multi-line Comments:
...
The content that is commented to
...
Variables: variables are represented by a variable name (the variable name must be a combination of case English, numbers and underscores _, and cannot start with a number)
Python, = is an assignment statement, you can copy any data type to a variable, the same variable can be duplicated repeatedly, and can be different types of data
Example: a=123 #a为整数
A= ' Imooc ' #a为字符串
This type of variable itself is called a dynamic language (it is not necessary to declare the variable type when defining the variable), and the corresponding year is the static language.
The static language must indicate the variable type when it is defined, and an error if the type does not match (for example, C + + language)
Understanding the representation of variables in computer memory:
A= ' ABC '
1. Create a string of ' ABC ' in memory
2. Create a variable named a in memory and point it to ' ABC '
Assigning a variable A to another variable B is actually pointing the variable B to the data that the variable a points to

Python Learning notes (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.