初识Python[Python常见问题]

01 Python简介

Python是一种跨平台的计算机程序设计语言。于1989年开发的语言,创始人范罗苏姆(Guido van Rossum),别称:龟叔(Guido)。

python具有非常多并且强大的第三方库,使得程序开发起来得心应手。

Python“信条”:人生苦短,我用python!(Life is short,you need Python。)

02 Python 版本

  • python 2.x 版本,官方在 2020 年停止支持,原码不规范,重复较多

  • python 3.x 版本,功能更加强大且修复了很多bug,原码清晰,简单

Let”s not play games with semantics. The way I see the situation for 2.7 is that EOL is January 1st, 2020, and there will be no updates, not even source-only security patches, after that date. Support (from the core devs, the PSF, and python.org) stops completely on that date. If you want support for 2.7 beyond that day you will have to pay a commercial vendor. Of course it”s open source so people are also welcome to fork it. But the core devs have toiled long enough, and the 2020 EOL date (an extension from the originally annouced 2015 EOL!) was announced with sufficient lead time and fanfare that I don”t feel bad about stopping to support it at all.【原文链接】

03 Python擅长的领域

  • Web开发:Django、pyramid、Tornado、Bottle、Flask、WebPy

  • 网络编程:Twisted、Requests、Scrapy、Paramiko

  • 科学运算:SciPy、Pandas、lpython

  • GUI图形开发:wxPython、PyQT、Kivy

  • 运维自动化:OpenStack、SaltStack、Ansible、腾讯蓝鲸

04 Python解释器(部分):

  • (1)Cpython(官方推荐):把python转化成c语言能识别的二进制码

  • (2)Jpython:把python转化成java语言能识别的二进制码

  • (3)其他语言解释器:把python转化成其他语言能识别的二进制码

  • (4)PyPy:将所有代码一次性编译成二进制码,加快执行效率(模仿编译型语言的一款python解释器)

05 2020年10月TIOBE指数

TIOBE指数

06 Python环境的安装

Windows

下载安装包:https://www.python.org/downloads/

配置环境变量:【右键计算机】–>【属性】–>【高级系统设置】–>【高级】–>【环境变量】–>【在系统变量中找到 Path,双击或编辑】–>【添加Python安装目录,如;C:python38,切记前面有英文标点分号(win10系统变量与win7大体一致)】

添加环境变量

Linux、Mac

无需安装,系统自带Python环境,但是可选择升级版本。

07 编写第一个Python程序

print("Hello World!")

08 编译型与解释型语言区别(补充)

  • 编译型:一次性把所有代码编译成机器能识别的二进制码再运行
    • 代表语言:c,c++
    • 优点:执行速度快
    • 缺点:开发速度慢,调试周期长
  • 解释型:代码从上到下一行一行解释并运行:
    • 代表语言:python,php
    • 优点:开发效率快,调试周期短
    • 缺点:执行速度相对慢

09 与其它编程语言的对比

C++

#include <iostream>
using namespace std;
int main()
{
   cout << "Hello World";
   return 0;
}

C

#include <stdio.h>
int main()
{
   /* 我的第一个 C 程序 */
   printf("Hello, World! 
"); 
   return 0;
}

C#

using System;
namespace HelloWorldApplication
{
   class HelloWorld
   {
      static void Main(string[] args)
      {
         /* 我的第一个 C# 程序*/
         Console.WriteLine("Hello World!");
         Console.ReadKey();
      }
   }
}

Java

public class HelloWorld {
    public static void main(String []args) {
       System.out.println("Hello World!");
    }
}

PHP

<?php
echo "Hello World!";
?>

Ruby

puts "Hello World!";

Go

package main
import "fmt"
func main() {
   fmt.Println("Hello, World!")
}

Python

print("Hello, World!");

10 Python之禅(扩展)

import this

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren”t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you”re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it”s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let”s do more of those!

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » 初识Python