python的入门学习:python代码实现的过程

python代码实现的过程

编译性语言:速度快,跨平台性差
解释性语言:速度慢,跨平台性好(python,shell)
python适应于短期开发,易读性强,开发速度快,运行速度相对慢,面向对象将要做的事情分配给其他人,是一种解决
问题的方式,重要的是分配给谁。
python的源程序就是.py结尾,python统一缩进,没有;号
 

领取Python学习资料可以加小编的微信:tz2020jd

python的入门学习:python代码实现的过程

python程序是如何执行的?
计算机中包含有较多的硬件,但是一个程序要运行,有三个核心的硬件,分别是:
1.cpu(cpu 就是干活的,离开了 cpu 电脑就不能干活)
中央处理器,是一块超大规模的集成电路
负责处理数据/计算
2.内存(临时存储数据 以 G 为单位 4G 8G 16G 32G)
临时存储数据(断电之后,数据会消失)
速度快
空间小(单位价格高)
3.硬盘(永久存储数据 以 T 为单位 1T=1024G)


永久存储数据
速度慢
空间大(单位价格低)
思考题:
1.计算机中哪一个硬件设备负责执行程序?
CPU
2.内存的速度快还是硬盘的速度快?
内存
3.我们的程序是安装在内存中的,还是安装在硬盘中的?
硬盘
4.我买了一个内存条,有 500G 空间,这句话对麼?
不对,内存条通常只有 4G/8G/16G/32G
5.计算机关机之后,内存中的数据都会消失麼?
是的
程序执行的原理
1.程序运行之前,程序是保存在硬盘中的
2.当要运行一个程序的时候,操作系统会首先让 CPU 把程序复制到内存中,
CPU 执行内存中方的代码程序,程序要执行,首先要被加载到内存。

python的入门学习:python代码实现的过程

python的入门学习:python代码实现的过程
 

安装常用的python解释器:
什么是ipython:
IPython是一个交互式计算系统。主要包含三个组件:增加的交互式 “Python shell”,解耦的双过程通信模型,交互式并行
计算的架构。支持变量自动补全。IPython 是一个 python 的交互式 shell,比默认的python shell好用得多,支持变量自动
补全,自动缩进,支持 bash shell命令,内置了许多很有用的功能和函数。IPython 是基于BSD 开源的。IPython 为交互式
计算提供了一个丰富的架构,包含:强大的交互式, shellJupyter 内核交互式的数据可视化工具灵活、可嵌入的解释器易于
使用,高性能的并行计算工具。


ipython的安装:
[[email protected] Desktop]$ su
Password: 
[[email protected] Desktop]# 
[[email protected] Desktop]# ls
3.jpg              Discuz_X3.2_SC_UTF8.zip                 python第一天
59f01d9c531b7.jpg  phpMyAdmin-3.4.0-all-languages.tar.bz2  考试博客
[[email protected] Desktop]# cd python第一天/
[[email protected] python第一天]# ls
ipython                            PycharmProjects  变量.pdf    变量的命名.pdf
pycharm-community-2016.3.2.tar.gz  python           变量的命名  截图
[[email protected] python第一天]# cd ipython/    自己下载的ipython安装包
[[email protected] ipython]# ls
openpgm-5.2.122-2.el7.x86_64.rpm
python-ipython-3.2.1-1.el7.noarch.rpm
python-ipython-console-3.2.1-1.el7.noarch.rpm
python-ipython-gui-3.2.1-1.el7.noarch.rpm
python-jsonschema-2.3.0-1.el7.noarch.rpm
python-mistune-0.5.1-1.el7.x86_64.rpm
python-path-5.2-1.el7.noarch.rpm
python-pip-7.1.0-1.el7.noarch.rpm
python-pygments-1.4-9.el7.noarch.rpm
python-simplegeneric-0.8-7.el7.noarch.rpm
python-zmq-14.3.1-1.el7.x86_64.rpm
zeromq3-3.2.5-1.el7.x86_64.rpm
[[email protected] ipython]# yum install * -y   安装ipython
[[email protected] ipython]# ipython  打开ipython的交互式界面
Python 2.7.5 (default, Feb 11 2014, 07:46:25) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: exit()   两种退出方式还有一种是ctrl+D
[[email protected] kiosk]# ipython 退出方式2
Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 
Do you really want to exit ([y]/n)? y   按组合键ctrl+D
 

python的入门学习:python代码实现的过程

ipython的简单使用:
行注释和块注释(多行注释)
python单行注释#和文字中间加空格
程序是用来处理数据的,在程序的内部,为用户密码开辟的空间叫做变量
变量必须先定义再使用:

[[email protected] kiosk]# ipython   打开ipython交互界面
Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: name = 1   定义变量
In [2]: name   不需要print可以直接调用变量名字
Out[2]: 1
exit()退出
In [3]: exit()
 

python的入门学习:python代码实现的过程

In [1]: name='薛飞龙'

In [2]: type(name)   字符串类型,type内置函数作用就是查看类型
Out[2]: str

In [3]: age = 18

In [4]: type(age)   整型
Out[4]: int

In [5]: gender=True

In [6]: type(gender)  布尔类型
Out[6]: bool

In [7]: height=1.8

In [8]: type(height)   浮点型
Out[8]: float

In [9]: type(2**32)
Out[9]: int
In [10]: type(2**64)  长整型,整型的一种分类
Out[10]: long
 

python的入门学习:python代码实现的过程

In [11]: i=10   不同类型之间可以进行计算

In [12]: f=10.5

In [13]: b=True

In [14]: i*f
Out[14]: 105.0

In [15]: f/i
Out[15]: 1.05

In [16]: i+f
Out[16]: 20.5

In [17]: f - b   布尔类型True代表1False代表0
Out[17]: 9.5

In [18]: a='xuefeilong'

In [19]: b='18sui'

In [20]: a + b   字符串的拼接
Out[20]: 'xuefeilong18sui'

In [21]: a*10  多次打印字符串
Out[21]: 'xuefeilongxuefeilongxuefeilongxuefeilongxuefeilongxuefeilongxuefeilongxuefeilongxuefeilongxuefeilong'

In [22]: (a + b)*2
Out[22]: 'xuefeilong18suixuefeilong18sui
 

python的入门学习:python代码实现的过程

In [23]: a + 10  字符串类型与整型不可以直接相加进行计算,需要进行类型转换
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-2c64baa9fdb5> in <module>()
----> 1 a + 10

TypeError: cannot concatenate 'str' and 'int' objects

In [24]: raw_input('please input a number')  交互式输入
please input a number123
Out[24]: '123'

In [25]: cc=raw_input('please input a number: ')    raw_input类型均为字符串类型,不可以乘法运算
please input a number: 134

In [26]: cc
Out[26]: '134'

In [27]: type(cc)
Out[27]: str

In [28]: age=raw_input('please input a number: ')   需要作乘法运算需要转换类型
please input a number: 18

In [29]: age
Out[29]: '18'

In [30]: type(age)
Out[30]: str
 

python的入门学习:python代码实现的过程

领取Python学习资料可以加小编的微信:tz2020jd