Python language is loved by many people in the IT industry because of its concise and clear style, as well as a large number of widely applicable class libraries and python open source frameworks that can be used. What is the origin and development history of Python? Let’s take a brief look at it.
Tracing back to the origin of the Python language, it was developed by Guido van Rossum in Amsterdam in the early 1990s as a new script interpreter. I wonder if Guido ever thought that Python would one day become one of the most popular programming languages?
Some people like to use glue language to describe Python because it can easily combine modules written in many other languages. As for the process, I won’t go into details here. If you are interested, you can find it anywhere. . What you need to know is that many universities at home and abroad also take the Python language as a required course, and the number of domestic units that use the Python language to work is also increasing. Programmers who know Python are in hot demand.
I would like to ask my friends who have learned Python language, what are its attractive features? Most people would think that it is a language that is easy to use, easy to read and easy to maintain, so many users like to use and learn it. It is really a language with a wide range of uses.
The most basic syntax of Python language is: indentation, control statements, expressions, functions, object methods, types and mathematical operations. Only after learning the basic syntax of Python can you start learning formal applications, such as: practical applications of graphics processing, mathematical processing, text processing, databases, WEB programming, crawlers, etc.
Python 3.3 is the latest version, but many people still like to start learning from python 2. Because it has been said before that the third-party support for Python 3 is not yet complete, you will encounter inexplicable problems during the learning process. It is better to start learning from python 2, which is already very complete. The transition to python 3 will be easy after that.
As can be seen from the above figure, the usage rate of python language is on the rise, and the usage rate of the top three languages is on the rise. Downtrend.
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 one of the most criticized shortcomings of Python. GIL is the Global Interpreter Lock (Global Interpreter Lock), which is used by computer programming language interpreters to synchronize threads. Tools enable only one thread to be executed 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 detail in the thread and process chapters later.
1、下载安装包 2、安装 安装在C:\Python36 3、配置环境变量 【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用;分割】
1.解压 tar xf Python-3.6.2.tgz 2.编译安装 cd Python-3.6.2 ./configure --prefix=/usr/local/Python3.6 make make install 3.配置环境变量 vim /etc/profile PATH=/usr/local/Python3.6/bin:$PATH source /etc/profile 4.测试 python3.6
#!/usr/binl/env python #encoding: utf-8 #author: YangLei print("hello,world")
Declare variables
#!/usr/binl/env python #encoding: utf-8 #author: YangLei name = "yanglei" print(name)
Rules for variable definition:
#!/usr/binl/env python #encoding: utf-8 #author: YangLei input_name = input("Please enter your name: ") print("hi,%s" % input_name)
"hello world"
#!/usr/binl/env python #encoding: utf-8 #author: YangLei name = "yanglei" print("hi,%s" % name) #输出hi,yanglei
注:字符串是 %s;整数 %d;浮点数%f
移除空白
分割
长度
索引
切片
#!/usr/binl/env python #encoding: utf-8 #author: YangLei name = ["yanglei","jack","marry","andy"]
基本操作:
索引
切片
追加
删除
长度
切片
循环
包含
5、字典(无序)
#!/usr/binl/env python #encoding: utf-8 #author: YangLei user_info = {"name":"yanglei","age":23,"job":"IT"}
常用操作:
索引
新增
删除
键、值、键值对
循环
长度
比较运算:
赋值运算:
逻辑运算:
成员运算:
身份运算:
位运算:
运算符优先级:
场景一、用户登陆验证
#!/usr/binl/env python #encoding: utf-8 #author: YangLei input_user = input("Please enter your user name: ") input_password = input("Please enter your password: ") if input_user == "yanglei" and input_password == "123456": print("\033[32;1m%s login successfully\33[0m" % input_user) else: print("\033[31;1mThe user name or password error,please try again\033[0m")
场景二、猜年龄游戏
在程序里设定好你的年龄,然后启动程序让用户猜测,用户输入后,根据他的输入提示用户输入的是否正确,如果错误,提示是猜大了还是小了
#!/usr/binl/env python #encoding: utf-8 #author: YangLei guess_age = 50 input_age = int(input("Please enter your guess age: ")) if input_age > guess_age: print("\033[31;1mCan you guess what big\33[0m") elif input_age < guess_age: print("\033[31;1mCan you guess what small\33[0m") else: print("\033[32;1mYou guessed it\33[0m")
外层变量,可以被内层代码使用
#!/usr/binl/env python #encoding: utf-8 #author: YangLei count = 1 while count <= 10: if count == 5: count += 1 continue print(count) count += 1
#!/usr/binl/env python #encoding: utf-8 #author: YangLei count = 1 while count <= 10: if count == 5: count += 1 break print(count) count += 1
由此可以看出continue是跳出当前循环,而break是跳出本层循环。
场景一、用户登陆验证升级
#!/usr/bin/env pyhon #encoding: utf-8 #auth: yanglei count = 0 while count < 3: input_user = input("Please enter your user name: ") input_password = input("Please enter your password: ") if input_user == "yanglei" and input_password == "123456": print("\033[32;1m%s login successfully\33[0m" % input_user) break elif count == 2: print("\033[31;1mThe user name or password mistake,three chances to use up,the program exits\33[0m") break else: count += 1 print("\033[31;1mThe user name or password error,please try again\033[0m")
场景二、猜年龄游戏升级
#!/usr/bin/env pyhon #encoding: utf-8 #auth: yanglei guess_age = 50 count = 0 while count <= 3: if count == 3: input_choose = input("Do you want to continue to play?(Y or y|N or n)") if input_choose == "Y" or input_choose == "y": count = 0 continue elif input_choose == "N" or input_choose == "n": break else: print("\033[31;1mAre you input errors!\33[0m") continue input_age = int(input("Please enter your guess age: ")) if input_age > guess_age: print("\033[31;1mCan you guess what big\33[0m") count += 1 elif input_age < guess_age: print("\033[31;1mCan you guess what small\33[0m") count += 1 else: print("\033[32;1mYou guessed it\33[0m") break
The above is the detailed content of Introduction to the origin and use of Python. For more information, please follow other related articles on the PHP Chinese website!