Home > Article > Backend Development > What are the main application areas of Python? Introduction to Python
1. Introduction to Python . During the Christmas period of 1989, Guido van Rossum was killing time in Amsterdam, determined to develop a new script interpreter as an inheritance of the ABC language
Python can It is used in many fields, such as: data analysis, component integration, network services, image processing, numerical computing and scientific computing and many other fields. At present, almost all large and medium-sized Internet companies in the industry are using Python, such as: Youtube, Dropbox, BT, Quora (China Zhihu), Douban, Zhihu, Google, Yahoo!, Facebook, NASA, Baidu, Tencent, Autohome, Meituan etc.
Currently the main application fields of Python:
Cloud Computing
WEB Development
##Scientific operations, artificial intelligence
: Typical libraries NumPy, SciPy, Matplotlib, Enthought libraries,pandasSystem Operation and Maintenance
: Essential language for operation and maintenance personnelFinance
: quantitative trading, financial analysis, in the field of financial engineering , Python is not only used, but also used the most, and its importance is increasing year by year. Reason: As a dynamic language, Python has a clear and simple language structure, rich libraries, mature and stable, scientific calculation and statistical analysis are very good, the production efficiency is much higher than c, c++, java, especially good at strategy backtestingGraphic GUI
: PyQT, WxPython,TkInterPython applications in some companies:
Google: Google App Engine, code.google.com, Google earth, Google crawler, Google advertising and other projects are all heavily developed using Python
What is the difference between compilation and interpretation?
The interpreter
only interprets the program one by one into machine language for the computer to execute, so The running speed is not as fast as the compiled program.This is because the computer cannot directly recognize and execute the statements we write, it can only recognize machine language (in binary form )
Compiled vs InterpretedCompiled
Interpreted<br><br>Advantages: It has good platform compatibility and can run in any environment, provided that an interpreter (virtual machine) is installed. Flexible, you can modify it directly when modifying the code, and it can be deployed quickly without downtime for maintenance.
Disadvantages: It must be explained every time it is run, and the performance is not as good as compiled languages.
Advantages and disadvantages of Python
Advantages:
Python’s positioning is "elegant", "Clear" and "simple", so Python programs always seem simple and easy to understand. Beginners learning Python are not only easy to get started, but also can write very, very complex programs if they go deeper in the future.
The development efficiency is very high. Python has a very powerful third-party library. Basically, if you want to realize any function through the computer, the official Python library has corresponding modules to support it. Download it directly. After the call, development is carried out on the basis of the basic library, which greatly reduces the development cycle and avoids reinventing the wheel.
High-level language————When you write a program in Python, you don’t need to think about low-level details such as how to manage the memory used by your program
Portability - Due to its open source nature, Python has been ported to many platforms (with modifications to enable it to work on different platforms). If you carefully avoid using system-dependent features, then all of your Python programs can run without modification on almost any system platform on the market
Scalability———— — If you need a critical piece of your code to run faster or want certain algorithms to be kept private, you can write parts of your program in C or C++ and use them in your Python program.
Embeddability - You can embed Python into your C/C++ program to provide scripting functionality to your program users.
Disadvantages:
Slow speed. Python’s running speed is indeed much slower than C language, and it is also slower than JAVA. Therefore, this is also the main reason why many so-called experts disdain to use Python, but in fact, the slow running speed referred to here cannot be directly perceived by users in most cases, and must be reflected with the help of testing tools. For example, if you use C It took 0.01s to run a program, and 0.1s in Python. In this way, C language is directly 10 times faster than Python, which is very exaggerated, but you cannot directly perceive it with the naked eye, because the time that a normal person can perceive is the smallest The unit is about 0.15-0.4s, haha. In fact, in most cases, Python can fully meet your program speed requirements, unless you want to write a search engine that has extremely high speed requirements. In this case, of course, it is recommended that you use C to implement it.
The code cannot be encrypted because PYTHON is an interpreted language and its source code is stored in the form of text. However, I don’t think this is a disadvantage. If your project requires source code The code must be encrypted, so you shouldn't use Python to implement it in the first place.
Threads cannot take advantage of the problem of multiple CPUs. This is the most criticized shortcoming of Python. GIL is the Global Interpreter Lock (Global Interpreter Lock), which is used by computer programming language interpreters. A tool for synchronizing threads so that only one thread is executing at any time. Python threads are native threads of the operating system. It is pthread on Linux and Win thread on Windows. The execution of the thread is completely scheduled by the operating system. A python interpreter process has a main thread and multiple user program execution threads. Even on multi-core CPU platforms, parallel execution of multi-threads is prohibited due to the existence of GIL. Regarding the compromise solution to this problem, we will discuss it in the thread and process chapters later
Python installation
windows:
Download the installation package:
Linux:
No installation is required, the system comes with a Python environment. (If you come with version 2.X, please upgrade to 3.X by yourself)
Variable\Character Encoding
# Author:Aaron LI
name = 'Aaron Li'<br><br> print("My name is",name)
<span style="font-size: 16px">变量<br>上述代码声明了一个变量,其变量名为name,而变量name的值为:"Aaron Li"</span>
Definition of variables Rules:
<span style="font-size: 16px">1.变量名只能是 字母、数字或下划线的任意组合<br>2.变量名的第一个字符不能是数字<br>3.一些关键字不能声明为变量名:<br> ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']<br><br></span>
Character encoding
The Python interpreter is loading. py file, the content will be encoded (default ascill)
ASCII (American Standard Code for Information Interchange, American Standard Code for Information Interchange) is a computer coding system based on the Latin alphabet , mainly used to display modern English and other Western European languages, which can only be represented by up to 8 bits (one byte), that is: 2**8 = 256-1, so the ASCII code can only represent up to 255 symbols
About Chinese
为了处理汉字,程序员设计了用于简体中文的GB2312和用于繁体中文的big5。
GB2312(1980年)一共收录了7445个字符,包括6763个汉字和682个其它符号。汉字区的内码范围高字节从B0-F7,低字节从A1-FE,占用的码位是72*94=6768。其中有5个空位是D7FA-D7FE。
GB2312 支持的汉字太少。1995年的汉字扩展规范GBK1.0收录了21886个符号,它分为汉字区和图形符号区。汉字区包括21003个字符。2000年的 GB18030是取代GBK1.0的正式国家标准。该标准收录了27484个汉字,同时还收录了藏文、蒙文、维吾尔文等主要的少数民族文字。现在的PC平台必须支持GB18030,对嵌入式产品暂不作要求。所以手机、MP3一般只支持GB2312。
从ASCII、GB2312、GBK 到GB18030,这些编码方法是向下兼容的,即同一个字符在这些方案中总是有相同的编码,后面的标准支持更多的字符。在这些编码中,英文和中文可以统一地处理。区分中文编码的方法是高字节的最高位不为0。按照程序员的称呼,GB2312、GBK到GB18030都属于双字节字符集 (DBCS)。
有的中文Windows的缺省内码还是GBK,可以通过GB18030升级包升级到GB18030。不过GB18030相对GBK增加的字符,普通人是很难用到的,通常我们还是用GBK指代中文Windows内码。
显然ASCII码无法将世界上的各种文字和符号全部表示,所以,就需要新出一种可以代表所有字符和符号的编码,即:Unicode
Unicode(统一码、万国码、单一码)是一种在计算机上使用的字符编码。Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制编码,规定虽有的字符和符号最少由 16 位来表示(2个字节),即:2 **16 = 65536,<br>注:此处说的的是最少2个字节,可能更多
UTF-8,是对Unicode编码的压缩和优化,他不再使用最少使用2个字节,而是将所有的字符和符号进行分类:ascii码中的内容用1个字节保存、欧洲的字符用2个字节保存,东亚的字符用3个字节保存...
所以,python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill)
注释
单行注释: #被注释内容
多行注释: """被注释内容""" 或者 '''被注释内容'''
用户交互
<br>
# Author:Aaron LI<br><br>username = input("username:") <br>password = input("password:")<br>print (username,password)
字符串拼接
#namne = input("name")<br>#age = input("age")<br>#job = input("job")<br>#salary = input("salary")<br>#info = """<br>#---------- into of %s ---------<br>#name:%s<br>#age:%s<br>#job:%s<br>#salary%s<br>#""" % (namne,namne,age,job,salary) %占位符跟上边的变量拼接起来<br>#print(info)<br># % DAY 1(10) 10:50处<br><br><br>#name = input("name")<br>#age = int(input("age"))<br>#job = input("job")<br>#salary = input("salary")<br><br>#info = """<br># ---------- into of %s-----------------<br># name:%s<br># age:%d<br># job:%s<br># salary:%s<br>#""" % (name,name,age,job,salary)<br>#print (info)<br><br>#推崇用此方法<br>name = input("name")<br>age = input("age")<br>job = input("job")<br>salary = input("salary")<br>info = """<br> ----------info of {_name} --------------<br> name:{_name}<br> age:{_age}<br> job:{_job}<br> salary:{_slary}<br>""" . format(_name=name,<br>_age=age,<br>_job=job,<br>_slary=salary)<br>print(info)<br>
将密码设为密文输出
利用getpass模块
import getpass<br>username = input("username:")<br>password = input("password:")<br>
print(username,password)
#在pycharm中无法输出测试
表达式 if......else
提示输入用户名和密码,验证用户名和密码
如果成功,则输出欢迎
如果错误,则输出,用户名和密码
# Author:Aaron LI<br><br>import getpass<br><br>_username = 'lixiguang'<br>_password = 'abc123'<br>username = input("username:")<br>password = input("password:")<br><br>if _username == username and _password == password:<br>print("Welcome user {name} login......".format(name=username))<br>else:<br>print("Invalid username or password!")
猜年龄
在程序中预先设定好年龄,启动程序后让用户猜测,根据用户的输入提示输入的正确与否,如果错误则给出提示
# Author:Aaron LI<br><br>age_of_lxg = 25<br>guess_age = int(input("guess age:"))<br><br>if age_of_lxg == guess_age:<br>print("Input correct!")<br>elif age_of_lxg > guess_age:<br>print("The input digit is too large")<br>else:<br>print("The input numbers are too small")
表达式for循环
for i in range(0,15):<br>print("Aaron",i)<br><br>
for i in range(0,19,2):<br>print("loop",i) #2 每执行一个跳一个 (步长)
<br>
# Author:Aaron LI<br>age_of_lxg = 28<br>for i in range(3):<br> guess_age = int(input("guess_age:") )<br>if guess_age == age_of_lxg:<br>print("yes,you got it.")<br>break<br> elif guess_age > age_of_lxg:<br>print("thine smaller....")<br>else:<br>print("think bigger!")<br>else:<br>print("you have tried too times..")
<br>
表达式while循环
count = 0<br>while True:<br>print("count:",count)<br> count +=1 #count = count +1<br><br>
# Author:Aaron LI<br><br>age_of_lxg = 28<br>count = 0<br>while count < 3:
guess_age = int(input("guess age:"))
if guess_age == age_of_lxg:
print("yes,you got it.")
break
elif guess_age > age_of_lxg:<br>print("think smaller...")<br>else:<br>print("think bigger...")<br> count +=1<br> if count == 3:<br> coutine_confim = input("do you want to keep guessing.....?")<br>if coutine_confim != 'n':<br> count = 0
<br>
break和continue<br>
<br>
count = 0<br>while True:<br>print("count:",count)<br> count +=1 #count = count +1<br> if count == 1001:<br>break #满足条件结束整个循环
<br>
for i in range(0,10):<br>if i <3:<br>print("loop",i)<br>else :<br>continue #跳出本次循环,进入下次循环<br> print("haha.....")
<br>
The above is the detailed content of What are the main application areas of Python? Introduction to Python. For more information, please follow other related articles on the PHP Chinese website!