Python3 Learning (1)-Basic film

Source: Internet
Author: User
Tags sublime text

  • Install (MAC)
    • Run directly:
      Install Python3

    • Input: Python3--version, check to verify that the installation was successful (must be python3)
  • Python interpreter
    • CPython
      • This interpreter is available in the installation package downloaded from the official website. is also the most used interpreter. Interpreter written with C
    • Ipython use
      • The interactive interpreter was enhanced on the basis of CPython, and the execution of Python code was consistent with CPython.
    • PyPy
      • With JIT technology, Python is dynamically compiled to improve the execution speed of Python.
    • Jython
      • Python interpreter running on the Java platform, compiling python into Java bytecode
    • IronPython
      • Run the Python interpreter on the. NET platform and compile the python into. NET bytecode
  • Write your first Python program and run a python program
      • Create a new file "hello.py" with content (recommended tool: Sublime Text, notepad++):
      • Print ('hello,world! ')
      • Console into this file directory, enter: Python3 hello.py
      • Python3 hello.py: Supports CPython interpreter to directly execute source code files in hello.py
  • Python Basics
    • Data type
      • Integer: Python can handle integers of any size, including, of course, negative integers, which are represented in the program in the same way as mathematically. such as: 1,-1,0,999999
      • Floating-point number: Fractional, supports scientific notation, supports values of any size. such as: 1.0,5.0,-1.9,5.1e2
      • String: Any text enclosed in single quotation marks and double quotation marks. If you still need single or double quotation marks in the text, you can use the escape character "\" such as: ' A ', "123aaa", 'a\ ' b\"(the string to be expressed: a ' B ')
      • Boolean value: A Boolean value that has a value of true, false, two, and is case -sensitive.
      • Null: None, with 0 (number) is different, 0 is meaningful, None is a special null value.
    • Variable
      • is made up of uppercase and lowercase English, numerals, or underscores, and cannot begin with a number. such as: a12,_a2,a_1123,123a ( illegal )
      • The type is immutable after the variable is assigned, but the value can be arbitrarily changed
    • Constant
      • It is recommended that all uppercase letters be named. such as: pi=3.1415926
    • Placeholder
      • %d Integer
        %s String
        %f Floating point number
        %x 10 binary integers
    • List
      • List: Ordered set, such as listt=[' AAA ', ' BBB ', ' CCC ']
      • Gets the number of elements in the list Len (), such as: Len (LISTT)-->3
      • Use the index directly to get the specified element content in the list. Starting with 0, the index of the last element is reduced by 1 for the total number of elements. such as:listt[0]--> ' AAA ',listt[1]--> ' BBB '
      • You can use the reciprocal index. such as:listt[-1]--> ' CCC ',listt[-2]--> ' BBB '
      • Adds an element that is automatically appended to the append (value). such as: Listt.append (' ddd '), result for listt[3]--> ' DDD '
      • Adds an element to the specified location, insert (Index,value). such as: Listt.insert (1, ' Insert '), the result is:listt[1]--> ' Insert ',listt[2]--> ' BBB '
      • Delete the non-trailing element, pop (). such as: List.pop (), the result is listt in the ' DDD ' element is deleted, the length of Listt minus 1
      • You can assign or change the contents of a value directly to a specified element. such as: listt[0]= ' BBB ', resulting in the first element of LISTT into ' BBB '
      • The element types in the list can be of many types, and the elements in the list can also be lists (multi-level nesting, multidimensional lists)
    • Meta-group
      • Tuple: Tuples cannot be modified after initialization. such as tuplet= (' Jack ', ' Leon ', ' Mike ')
      • There is no append (), insert () method,
    • Dictionary
      • Dict: Use key-value (Key-value) storage, with extremely fast lookup speed. Such as:d = {‘Michael‘: 95, ‘Bob‘: 75, ‘Tracy‘: 85}
      • Gets the value in the dictionary. such as: d[' Michael ']-->95
      • Assigns a value to a key in the dictionary. such as: d[' Michael ']=100, results for d[' Michael ']-->100
      • Delete the specified key and value (deleted) from the dictionary, pop (' key '). such as: D.pop (' Bob '), the result is the D Dictionary of d[' Michael ']=75 is deleted, only 2 key values left
    • Set
      • The set of unordered and non-repeating elements in mathematical sense
    • Conditional judgment
      • if < condition judgment 1>:    < execute 1>elif < condition 2>    :< execute 2>elif < condition judgment 3>:    < execute 3>else:    < Execute 4>
      • Note: a colon ":" is required after each judgment.
    • Cycle
      • for...in ...
        • iterates through each element of the list or tuple in turn
        •  names = [ '  michael  , "  bob  , "    " ]   name in   names:  print  (name) 
      • while ...
        • as long as the condition is met, loop continuously, exit the loop when the condition is not satisfied
        •  sum = 0n  = 99while  n > 0:sum  = sum + n n  = N-2print  (sum) 
  • Function
    • function name, parameter, return value
    • Default parameter: When parameters are not passed, there is a default value
    • Parameters
      • Variable parameter: *args is a variable parameter, and args receives a tuple
      • Keyword parameter: **kw is the keyword parameter, kw is receiving a dict
    • A function can return multiple return values at the same time
    • Import Math def Move (x, y, step, angle=0):    = x + step * math.cos (angle)    = y-step * Math. Sin (angle)    return NX, NY

Python3 Learning (1)-Basic film

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.