Basic concepts and knowledge----python basics

Source: Internet
Author: User
Tags sublime text virtual environment virtualenv

Tidy up the basic concepts and knowledge of Python, mainly using Python3 as the grammar standard.

Python Introduction

An object-oriented interpretive computer design language with rich and powerful libraries.

    • Python positioning: "Elegant", "clear", "simple"
    • A variety of application scenarios: can write tools, background services, mobile and so on.


Operating Environment construction

Download the corresponding version of the Python installation, the official website address is as follows

https://www.python.org/

Run get-pip.py install Pip (Py3 comes with PIP)

https://bootstrap.pypa.io/get-pip.py

Adding Python directories and scripts subdirectories to environment variables

Install the virtual environment

    • Installing Virtualenv
Pip Install Virtualenv
    • If configured correctly, it will enter the Python interpreter interface
Python 3.5.2 (V3.5.2:4DEF2A2901A5, June, 22:01:18) [MSC v.1900 + bit (Intel)] on Win32type "help", "copyright", "C Redits "or" license "for more information.>>>

Editor selection

Sublime text,wing Ide,pycharm

basic syntax and Concepts

Variable

>>> x=3>>> x*26>>> x*9992997

  

Integer, floating-point number

x=567 (integer) y=5.67 (floating-point) x/y (default return floating-point number) x//y (return integer by default)

  

Function

def checkishascapitalletter (filename):    if filename.islower () = = true:        return True    else:        Common.outerror (filename + "file name in uppercase ...") "Return Fasle" (...)                    

  

Indentation, flow control statements For,if,while and so on are identified by indentation, and functions are

For I in range (0, 5):    print (i)


Module

>>>import Common (allows the use of namespaces to access things in the common) >>>common.count () >>>from Common import count ( Add to current namespace) >>>count ()

  

Execute Python Program

Python.exe test.py

Common data structures
    • Listing (list)
    • Dictionary (dict)
    • Collection (SET)
    • Tuple (tuple)

Common data types
    • Integer
    • Floating point number
    • Boolean value
    • String
String Basics

Strings can not be changed, as in Java, if you assign a value, it is actually a new string

String definition, can be single or double quotes, character stitching with + number

>>> "Hello World", ' Hello World ' >>> ' Hello World ' Hello World ' >>> ' hello ' + ' world ' HelloWorld ' >>> ' don ' t let go ' "Don't let Go" >>> ' don\ ' t let go ' (Escape single quotes) "Don't Let Go" >>> "don\ t let go" "do N ' t let go ">>> r" don\ ' t Let go "(front with" R "not escaped)" don\\ t Let go "

  

String Lookup

>>> "Nothing is here." Find ("see") 11>>> ' nothing to see here '. Find ("OK")-1

  

String formatting

>>> filename = "notepad" >>> "Get file:%s OK"%filename ' Get file:notepad OK '


The Unicode,python3 string is a Unicode-encoded
1. Convert other string formats to Unicode:

Ret=str.decode ("gb2312") Ret=str.decode ("ASCII") Ret=str.decode ("Utf-8")


2. Convert Unicode characters to other string formats:

Ret=str.encode ("gb2312") Ret=str.encode ("ASCII") Ret=str.encode ("Utf-8")


Regular expressions

Http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

 

Extended

String built-in function, Len (), Split (), Upper (), strip () multi-line string subscript [0],[-2]

  

Basic concepts and knowledge----python basics

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.