• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

初识Python

python 搞java代码 3年前 (2022-05-21) 21次浏览 已收录 0个评论

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指数

06 Python环境的安装

Windows

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

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

Linux、Mac

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

07 编写第一个Python程序

<code class="language-python">print("Hello World!")
</code>

www#gaodaima.com来源gaodai#ma#com搞@代~码网搞代码

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

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

09 与其它编程语言的对比

C++

<code class="language-cpp">#include <iostream>
using namespace std;
int main()
{
   cout << "Hello World";
   return 0;
}
</code>

C

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

C#

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

Java

<code class="language-java">public class HelloWorld {
    public static void main(String []args) {
       System.out.println("Hello World!");
    }
}
</code>

PHP

<code class="language-php"><?php
echo "Hello World!";
?>
</code>

Ruby

<code class="language-ruby">puts "Hello World!";
</code>

Go

<code class="language-go">package main
import "fmt"
func main() {
   fmt.Println("Hello, World!")
}
</code>

Python

<code class="language-python">print("Hello, World!");
</code>

10 Python之禅(扩展)

<code class="language-python">import this
</code>

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!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:初识Python

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址