Python basics ---- basic concepts and knowledge, python ----
Sort out the basic concepts and knowledge of python, and use python3 as the syntax standard.
Python Introduction
An Object-Oriented explanatory computer design language with rich and powerful libraries.
- Python positioning: "elegant", "clear", and "simple"
- Multiple application scenarios: Write tools, backend services, and mobile terminals.
Build running environment
Download the corresponding version of Python installation. The official website address is as follows:
https://www.python.org/
Run a get-pip.py to install pip (Py3 comes with pip)
https://bootstrap.pypa.io/get-pip.py
Add the python directory and Scripts subdirectory to the Environment Variable
Install Virtual Environment
pip install virtualenv
- If the configuration is correct, the python interpreter interface is displayed.
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>
Select Editor
Sublime Text, Wing IDE, pycharm
Basic syntax and concepts
Variable
>>> x=3>>> x*26>>> x*9992997
Integer and floating point number
X = 567 (integer) y = 5.67 (floating point number) x/y (default return floating point number) x // y (default return integer)
Function
Def checkIsHasCapitalLetter (filename): if filename. islower () = True: return True else: common. outError (filename + "the file name is capitalized ................. ") return Fasle
Indentation, process control statements for, if, while, etc. all rely on Indentation recognition, and functions are also
for i in range(0, 5): print(i)
Module
>>> Import common (allow namespaces to access things in common) >>> common. count () >>> from common import count (added to the current namespace) >>> count ()
Run the python Program
python.exe test.py
Common Data Structures
- List)
- Dictionary (dict)
- Set)
- Tuple)
Common Data Types
- Integer
- Floating Point Number
- Boolean Value
- String
String Basics
The string cannot be changed. It is the same as java. If a value is assigned, a new string is created.
String definition, which can be single quotation marks or double quotation marks. + is used for character concatenation.
>>> "Hello world" 'Hello world' >>> "hello" + "world" 'helloworld' >>> "don 'tlet go "" don't let go ">>> 'Don \'t let go '(escape single quotes) "don't let go" >>> "don \'t let go" "don't let go" >>> r "don \'t let go" (front "r" does not escape) "don \'t let go"
String search
>>> "nothing to see here".find("see")11>>> "nothing to see here".find("ok")-1
String formatting
>>> filename = "notepad">>> "get file: %s ok"%filename'get file: notepad ok'
UNICODE, python3 string is 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 Expression
http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html
Extension
String built-in functions, len (), split (), upper (), strip () multi-line string subscript [0], [-2]