This is the best Python tutorial I've ever seen: ten minutes to get to know python

best python tutorial ve seen

This article mainly introduces the concise ten minutes Python Introductory tutorial ,Python The simplicity of the language itself also makes all kinds of Python The introduction to shutter is very popular , This paper is one of the articles in China , Friends in need can refer to

【 brief introduction 】

Python It's a dynamically interpreted programming language .Python Can be in Windows、UNIX、MAC And other operating systems , It can also be in Java、.NET Development platform .

【 characteristic 】

1 Python Use C Language development , however Python No more C Complex data types such as pointers in languages .

2 Python It has strong object-oriented characteristics , And it simplifies the object-oriented implementation . It eliminates the type of protection 、 abstract class 、 Object oriented elements such as interfaces .

3 Python Code blocks use spaces or tab indents to separate code .

4 Python have only 31 A reserved word , And there's no semicolon 、begin、end Wait for the sign .

5 Python It's a strongly typed language , After the variable is created, it will correspond to a data type , Different types of variables that appear in a unified expression need to be typed .

【 Build development environment 】

1 You can go to Download installation package , And then through configure、make、make install Installation .

2 You can also go to To download ActivePython The component package .(ActivePython It's right Python Binary packaging of core and common modules , It is ActiveState Issued by the company Python development environment .ActivePython bring Python It's easier to install , And can be applied to a variety of operating systems .ActivePython Some common Python Expand , as well as Windows Programming interface of environment ). Yes ActivePython Come on , If you are windows user , download msi Just install the package ; If you are Unix user , download tar.gz The package can be decompressed directly .

3 Python Of IDE, Include PythonWin、Eclipse+PyDev plug-in unit 、Komodo、EditPlus

【 edition 】

python2 And python3 It's the two major versions at the moment .

In the following two cases , It is recommended to use python2:

1 When you have no complete control over the environment you are about to deploy ;

2 When you need to use certain third-party packages or extensions ;

python3 It's officially recommended and fully supported in the future , At present, many function improvements are only in python3 On the version .

 This is the best I've ever seen Python course : Ten minutes to meet you Python

 Xiaobian is a python Development Engineer , Here I have a new set of my own python System learning course , Including from the foundation of python Script to web Development 、 Reptiles 、 Data analysis 、 Data visualization 、 Machine learning, etc . Those who want these materials can pay attention to Xiaobian , And in the backstage private letter small make up :“07” Can receive .

【hello world】

1 establish

2 Programming :
if __name__ == \'__main__\': print "hello word" 

3 Run the program :
python ./ 

【 notes 】

1 Whether it's line comments or paragraph comments , in # Add a space to comment .

2 If you need to use Chinese comments in your code , Must be in python The following comments are added at the beginning of the document :

# -* - coding: UTF-8 -* -

3 The following comment specifies the interpreter
#! /usr/bin/python

【 file type 】

1 Python The file types are divided into 3 Kind of , Source code 、 Byte code and optimization code . All of these can be run directly , There is no need to compile or connect .

2 Source code to .py Extension name , from python To explain ;

3 The source file is compiled and generated with the extension .pyc The file of , The compiled byte file . This file cannot be modified with a text editor .pyc Files are platform independent , Can run on most operating systems . The following statement can be used to generate pyc file :
import py_compilepy_compile.compile(‘') 

4 The optimized source file will be .pyo For the suffix , That is to optimize the code . It can't be modified directly with a text editor , The following command can be used to generate pyo file :

python -O -m py_complie 

【 Variable 】

1 python Variables in do not need to be declared , The operation of variable assignment is the procedure of variable declaration and definition .

2 python A new assignment in , A new variable will be created . Even if the name of the variable is the same , The identifications of variables are not the same . use id() Function to get the variable ID :
x = 1print id(x)x = 2print id(x) 

3 If the variable is not assigned , be python It is assumed that the variable does not exist

4 Variables defined outside a function can be called global variables . Global variables can be accessed by any function inside the file and by any external file .

5 Global variables should be defined at the beginning of the file .

6 You can also put global variables in a special file , And then through import To quote : The contents of the document are as follows :

Xiaobian is a python Development Engineer , Here I have a new set of my own python System learning course , Including from the foundation of python Script to web Development 、 Reptiles 、 Data analysis 、 Data visualization 、 Machine learning, etc . Those who want these materials can pay attention to Xiaobian , And in the backstage private letter small make up :“07” Can receive .

_a = 1_b = 2 Reference global variables in :
import gldef fun(): print gl._a print gl._bfun() 

【 Constant 】

python There is no reserved word to define constants in . You can define a constant class to realize the function of constant .
class _const: class ConstError(TypeError): pass def __setattr__(self,name,vlaue): if self.__dict__.has_key(name): raise self.ConstError, “Can't rebind const(%s)”%name self.__dict__[name]=valueimport syssys.modules[__name__]=_const() 

【 data type 】

1 python The number types of are divided into integer types 、 Long integer 、 floating-point 、 Boolean type 、 Plural type .

2 python There is no character type

3 python There is no common type inside , Any type is an object .

4 If you need to see the type of the variable , have access to type class , This class can return the type of the variable or create a new type .

5 python Yes 3 There are two ways to represent string types , Single quotation marks 、 Double quotes 、 Three quotes . Single quotation marks and double quotation marks work the same way .python Programmers prefer single quotes ,C/Java Programmers are used to using double quotation marks to represent strings . You can enter single quotation marks in three quotation marks 、 Characters such as double quotes or newlines .

【 Operators and Expressions 】

1 python Autoincrement and autodecrement operators are not supported . for example i++/i- It's wrong. , but i+=1 Yes. .

2 1/2 stay python2.5 It would have been equal to 0.5, stay python2.5 And then it will be equal to 0.

3 It's not equal to != or <>

4 Equal to == Express

5 In logical expressions and Representation logic and ,or Represent logical or ,not Express logical not

【 Control statement 】

1 Conditional statements :
if ( expression ) : sentence 1else : sentence 2 

2 Conditional statements :
if ( expression ) : sentence 1elif ( expression ) : sentence 2…elif ( expression ) : sentence nelse : sentence m 

3 Conditions of nested :
if ( expression 1) : if ( expression 2) : sentence 1 elif ( expression 3) : sentence 2 … else: sentence 3elif ( expression n) : …else : … 

4 python There is no such thing as switch sentence .

5 Loop statement :
while( expression ) : …else : … 

6 Loop statement :
for Variable in aggregate : … else : … 

7 python Does not support similar c Of for(i=0;i<5;i++) Such a loop statement , But with the help of range simulation :
for x in range(0,5,2): print x 

 This is the best I've ever seen Python course : Ten minutes to meet you Python

【 Array correlation 】

1 Tuples (tuple):python A built-in data structure in . Tuples are made up of different elements , Each element can store different types of data , Such as a string 、 Numbers, even elements . Tuples are write protected , That is, the tuple cannot be modified after it is created . Tuples often represent a row of data , Elements in tuples represent different data items . You can think of tuples as immutable arrays . An example of creating a tuple is as follows :

2 list (list): Lists are similar to tuples , It's also made up of a set of elements , List can be added 、 Delete and find operations , The value of the element can be modified . A list is an array in the traditional sense . An example of creating a list is as follows :

have access to append Method to append elements to the tail , Use remove To delete the element .

3 Dictionaries (dictionary): By key - A collection of value pairs , The values in the dictionary are referenced by keys . The key is separated from the value by a colon , key - Value pairs are separated by commas , And it's contained in a pair of curly braces . The creation example is as follows :
dict={“a”:”apple”, “b”:”banana”, “g”:”grage”, “o”:”orange”} 

4 Sequence : Sequences are collections with indexing and slicing capabilities . Tuples 、 Lists and strings belong to sequences .

【 Function related 】

1 python The program is made up of packages (package)、 modular (module) And functions . A package is a collection of modules . A module is a collection of functions and classes that deal with a certain kind of problems .

2 A package is a toolbox for specific tasks .

3 The package must contain a file , It is used to identify that the current folder is a package .

4 python Our program is made up of modules . Modules organize a set of related functions or code into a file , A file is a module . The module consists of code 、 Functions and classes . The import module uses import sentence .

5 The function of package is to realize the reuse of program .

6 A function is a piece of code that can be called many times , An example of a function definition is as follows :
def arithmetic(x,y,operator): result={ “+”:x+y, “-“:x-y, “*”:x*y, “/”:x/y } 

7 Function return value can be used return To control .

【 String related 】

1 Format output :
format=”%s%d” % (str1,num)print format 

2 use + Merge strings :

3 String interception can be done through index / section , It can also be done through split function .

4 Slicing strings :
word=”world”print word[0:3] 

5 python Use == and != To compare strings . If the two variables being compared are of different types , Then the result must be different .

【 Document processing 】

1 Simple handling of files :

2 Reading files can use readline() function 、readlines() Functions and read function .

3 Writing to a file can use write()、writelines() function

 This is the best I've ever seen Python course : Ten minutes to meet you Python

【 Objects and classes 】

1 python use class Reserve words to define a class , The first character of the class name should be capitalized . When the type a programmer needs to create cannot be represented by a simple type , You need to define classes , Then create objects from the defined classes . Define class examples : class Fruit: def grow(self): print “Fruit grow”

2 When an object is created , There are three features , The handle to the object 、 Properties and methods . Method to create an object :
fruit = Fruit()fruit.grow() 

3 python There is no protection type modifier

4 Class methods are also divided into public methods and private methods . Private functions cannot be called by functions other than this class , Private methods cannot be called by external classes or functions .

5 python Using functions ”staticmethod()“ or ”@ staticmethod“ The method of instruction transforms ordinary functions into static methods . Static methods are equivalent to global functions .

6 python The constructor for is called __init__, The destructor is called __del__

7 How to use inheritance :
class Apple(Fruit): def … 

【 Connect mysql】

1 use MySQLdb Module operation MySQL The database is very convenient . The sample code is as follows :
import os, sysimport MySQLdbtry: conn MySQLdb.connect(host='localhost',user='root',passwd='',db='address'except Exception,e: print e sys.exit()cursor=conn.cursor()sql='insert into address(name, address) values(%s, %s)'value=((“zhangsan”,”haidian”),(“lisi”,”haidian”))try cursor.executemany(sql,values)except Exception, e: print esql=”select * from address”cursor.execute(sql)data=cursor.fetchall()if data for x in data: print x[0],x[1]cursor.close()conn.close() 

I hope the content of this article can help you , Happy New Year! !


One more sentence at the end , Xiaobian is a python Development Engineer , Here I have a new set of my own python System learning course , Including from the foundation of python Script to web Development 、 Reptiles 、 Data analysis 、 Data visualization 、 Machine learning, etc . Those who want these materials can pay attention to Xiaobian , And in the backstage private letter small make up :“07” Can receive .

本文为[The style of ancient Taoism and Confucianism]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database