0x00 前言
相信任何程序员邂逅任意一门编程语言后都会带着感恩的心去完成第一个程序, 这个程序的名字叫 Hello,World, 也是最著名的程序!
关于 Hello,World 程序的由来这里我就不再多多叙说了, 当然想要知道由来, 我就温馨的附上地址慢慢看吧! https://blog.csdn.net/testcs_dn/article/details/52673794
好, 聊回正题今天是学 python 第几天来着我忘记了, 很多讲师, 还有视频教程都说要写一个博客, 那就写嘛!
也就是从今天起, My A9kl 正式的开始学习这门语言了!
古往今来, 中国是很注重礼仪, 而且也是礼仪之邦 , 在拜师学艺前都会敬上三杯茶, 磕三个头, 当然我是自学我要崇敬的当然是搜索引擎了, 托搜索引擎的福今日
我 A9kl 正式入门 Python 带着感恩的心去写上我第一个程序: Hello, World.
0x01 准备环境及介绍
一, Python2.x-3.x 版本(任意)
二, Python 的发展历程
1989 年, 为了打发圣诞节假期, Guido 开始写 Python 语言的编译器. Python 这个名字, 来自 Guido 所挚爱的电视剧 Monty Python's Flying Circus. 他希望这个新的叫做 Python 的语言, 能符合他的理想: 创造一种 C 和 shell 之间, 功能全面, 易学易用, 可拓展的语言.
1991 年, 第一个 Python 编译器诞生. 它是用 C 语言实现的, 并能够调用 C 语言的库文件. 从一出生, Python 已经具有了: 类, 函数, 异常处理, 包含表和词典在内的核心数据类型, 以及模块为基础的拓展系统.
Granddaddy of Python web frameworks, Zope 1 was released in 1999
Python 1.0 - January 1994 增加了 lambda https://en.wikipedia.org/wiki/Lambda_calculus , map https://en.wikipedia.org/wiki/Map_(higher-order_function) , filter https://en.wikipedia.org/wiki/Filter_(higher-order_function) and reduce https://en.wikipedia.org/wiki/Fold_(higher-order_function) .
Python 2.0 - October 16, 2000, 加入了内存回收机制, 构成了现在 Python 语言框架的基础
Python 2.4 - November 30, 2004, 同年目前最流行的 WEB 框架 Django 诞生
- Python 2.5 - September 19, 2006
- Python 2.6 - October 1, 2008
- Python 2.7 - July 3, 2010
In November 2014, it was announced that Python 2.7 would be supported until 2020, and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible
- Python 3.0 - December 3, 2008
- Python 3.1 - June 27, 2009
- Python 3.2 - February 20, 2011
- Python 3.3 - September 29, 2012
- Python 3.4 - March 16, 2014
- Python 3.5 - September 13, 2015
当我们编写 Python 代码时, 我们得到的是一个包含 Python 代码的以. py 为扩展名的文本文件. 要运行代码, 就需要 Python 解释器去执行. py 文件.
三, 多种 Python 解释器
由于整个 Python 语言从规范到解释器都是开源的, 所以理论上, 只要水平够高, 任何人都可以编写 Python 解释器来执行 Python 代码(当然难度很大). 事实上, 确实存在多种 Python 解释器.
CPython
当我们从 Python 官方网站 https://www.python.org/ 下载并安装好 Python 2.7 后, 我们就直接获得了一个官方版本的解释器: CPython. 这个解释器是用 C 语言开发的, 所以叫 CPython. 在命令行下运行 python 就是启动 CPython 解释器.
CPython 是使用最广的 Python 解释器. 教程的所有代码也都在 CPython 下执行.
IPython
IPython 是基于 CPython 之上的一个交互式解释器, 也就是说, IPython 只是在交互方式上有所增强, 但是执行 Python 代码的功能和 CPython 是完全一样的. 好比很多国产浏览器虽然外观不同, 但内核其实都是调用了 IE.
CPython 用>>>作为提示符, 而 IPython 用 In [序号]: 作为提示符.
PyPy
PyPy 是另一个 Python 解释器, 它的目标是执行速度. PyPy 采用 JIT 技术 http://en.wikipedia.org/wiki/Just-in-time_compilation , 对 Python 代码进行动态编译(注意不是解释), 所以可以显著提高 Python 代码的执行速度.
绝大部分 Python 代码都可以在 PyPy 下运行, 但是 PyPy 和 CPython 有一些是不同的, 这就导致相同的 Python 代码在两种解释器下执行可能会有不同的结果. 如果你的代码要放到 PyPy 下执行, 就需要了解 PyPy 和 CPython 的不同点 http://pypy.readthedocs.org/en/latest/cpython_differences.html .
Jython
Jython 是运行在 Java 平台上的 Python 解释器, 可以直接把 Python 代码编译成 Java 字节码执行.
IronPython
IronPython 和 Jython 类似, 只不过 IronPython 是运行在微软. Net 平台上的 Python 解释器, 可以直接把 Python 代码编译成. Net 的字节码.
介绍完了, 就开始安装它!
0x02 安装
windows
1, 下载安装包
https://www.python.org/downloads/
2, 安装
默认安装路径: C:\python27
3, 配置环境变量
[右键计算机] --[属性] --[高级系统设置] --[高级] --[环境变量] --[在第二个内容框中找到 变量名为 Path 的一行, 双击] --> [Python 安装目录追加到变值值中, 用 ; 分割]
如: 原来的值; C:\python27, 切记前面有分号
Linux
无需安装, 原装 Python 环境
Ps: 如果自带 2.6, 请更新至 2.7
0x03 实战
创建一个文件叫 hello.py, 并输入
1 print("Hello World!")
交互器中执行, 调用 python 自带的交互器运行代码 (ps:Python 自带 IDLE 下[ F5] )
- Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
- Type "copyright", "credits" or "license()" for more information.
- >>>
- ==================== RESTART: C:\Users\91001\Desktop\1.py ====================
- Hello world!
- >>>
顺便附上其他语言的 Hello World!
- #include <stdio.h>
- int main(void)
- {
- printf("\nhello world!");
- return 0;
- }
- C
- C
- #include <iostream>
- int main(void)
- {
- std::cout<<"Hello world";
- }
- C++
- public class HelloWorld{
- // 程序的入口
- public static void main(String args[]){
- // 向控制台输出信息
- System.out.println("Hello World!");
- }
- }
- JAVA
- JAVA
- <?php
- echo "hello world!";
- ?>
- PHP
- 1 puts "Hello world."
- RUBY
- <html>
- <title></title>
- <body>
- <div align="center">
- Hello World !
- </div>
- </body>
- </html>
- HTML
- <span style="font-size:18px;">using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks; // 以上代码自动生成
- namespace Crazy // 声明命名空间
- {
- class HelloWorld // 类名
- {
- static void Main(string[] args) // 声明 Main 方法
- {
- Console.WriteLine("HelloWorld!");// 调用了 System.Console 类的 WriteLine()方法, 将制定数据写入标准输出流
- Console.ReadLine(); // 使程序暂停, 按回车, 程序继续运行
- }
- }
- }</span>
- C#
1 print("Hello world")
Lua 脚本语言
- Listing 1.10 Printing hello world (F#)
- let message = "Hello world!" [1]
- printfn "%s" message [2]
- F#
0x04 谢幕
完
来源: http://www.bubuko.com/infodetail-2685780.html