python基础1--安装、package、数据类型
1、下载python
下载地址https://www.python.org/downloads/

2、Package以及数据类型
自带package和外部package
自带package举例: os; os.getwd()
import os
import requests print(os.getcwd())
r = requests.get("http://www.baidu.com")
print(r.url)
print(r.encoding)
print(r.text)
外部package以及管理系统介绍: easy_install, pip
pip和easyinstall的区别:
1)pip会把插件及其相关的依赖一起安装而easyinstall只会安装制定的插件
2)pip继承easyinstall,即安装pip之前必须有easyinstall存在
Python 3.4以上版本已经带有,但在环境变量Path中配置相应路径,打开python安装目录中查看

配置后,在cmd中测试easy_install

测试pip

举例使用使用pip安装requests

3、Python数据类型
总体包含以下数据类型:numerics, sequences, mappings, classes, instances, and exceptions
Numeric Types包括 int (boolean类型被认为是int的一个特殊表现), float, complex(负数)
int: unlimited length
float: 对应的是C语言中的double类型, 可查看 sys.float_info
complex: real(实部) & imaginary(虚部),用z.real 和 z.imag来取两部分
具体运算以及法则参见:
|
Operation |
Result |
Full documentation |
|
x + y |
sum of x and y |
|
|
x - y |
difference of x and y |
|
|
x * y |
product of x and y |
|
|
x / y |
quotient of x and y |
|
|
x // y |
floored quotient of x and y |
|
|
x % y |
remainder of x / y |
|
|
-x |
x negated |
|
|
+x |
x unchanged |
|
|
abs(x) |
absolute value or magnitude of x |
|
|
int(x) |
x converted to integer |
|
|
float(x) |
x converted to floating point |
|
|
complex(re, im) |
a complex number with real part re, imaginary part im. im defaults to zero. |
|
|
c.conjugate() |
conjugate of the complex number c |
|
|
divmod(x, y) |
the pair (x // y, x % y) |
|
|
pow(x, y) |
x to the power y |
|
|
x ** y |
x to the power y |
import sys a = 3
b = 4
c = 5.66
d = 8.0
e = complex(c, d)
f = complex(float(a), float(b)) print ("a is type" , type(a))
print ("b is type" , type(b))
print ("c is type" , type(c))
print ("d is type" , type(d))
print ("e is type" , type(e))
print ("f is type" , type(f)) print(a + b)
print(d / c)
print (b / a)
print (b // a)
print (e)
print (e + f) print ("e's real part is: " , e.real)
print ("e's imaginary part is: " , e.imag) print (sys.float_info)
运行结果:

字符串:是指一串字符,示或者打印出来文字信息,不可变(immutable)。在python中有单引号,双引号,三引号的方式。Format字符串用于联合。换行符为" \n"
print("Hellow World")
print('Hellow World')
print('''This is 1 line
This is 2 line
this is 3 line
''')
age = 3
name = "Tom"
print("{0} was {1} years old.".format(name, age))
print(name + " was " + str(age) + " years old.")
运行结果:

字面常量(literal constant):
可以直接以字面的意义使用它们:
如:6,2.24,3.45e-3, "This is a string"
常量:不会被改变
变量:用于储存信息,属于identifier。其中identifier命名规则是第一个字符必须是字母或者下划线,其余字符可以是字母,数字,或者下划线。区分大小写。如:合法(i, name_3_4, big_bang)不合法(2people, this is tom, my-name, >123b_c2)
注释: #
缩进(Indentation):python的语法结构建立在缩进上
python基础1--安装、package、数据类型的更多相关文章
- python基础之五大标准数据类型
学习一门语言,往往都是从Hello World开始. 但是笔者认为,在一个黑框框中输出一个"你好,世界"并没有什么了不起,要看透事物的本质,熟悉一门语言,就要了解其底层,就是我们常 ...
- python基础及安装
一.python介绍 介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,Guido开始写能够解释Python语言语法的解释器.Python这个名 ...
- 【Python基础】安装python第三方库
pip命令行安装(推荐) 打开cmd命令行 安装需要的第三方库如:pip install numpy 在安装python的相关模块和库时,我们一般使用“pip install 模块名”或者“pyth ...
- Python基础之模块、数据类型及数据类型转换
一.模块 1.标准库 不需要安装,直接调入使用的模块. import sys模块: import sys print(sys.path) #打印环境变量绝对路径 print(sys.argv) #打印 ...
- python基础(二)-------数据类型
python开发基础篇(二)数据类型 python数据类型有: 1.数字 1.只能存放一个值 2.一经定义,不可更改 3.直接访问 主要的分类为:整型,长整型,(python2有长整型的概念Pytho ...
- python基础-第二篇-基本数据类型
一.运算符 1.算数运算: 算数运算符相信大家都不陌生吧,尤其是加减乘除,好!那我就带着大家看看最后三个,这三个到底是干什么玩意的? %,取两数相除的余数,看图: **,x的多少次幂,看图: //,取 ...
- Python基础语法,基本数据类型及相关操作
---恢复内容开始--- python文件 文件开头要有 #!/usr/bin/ python --在linux中是告诉系统phthon的路径是在/usr/bin/ python目录下 ...
- 第二章:Python基础の快速认识基本数据类型和操作实战
本课主题 字符串和操作实战 二进制操作实战 List 列表和操作实战 Tuple 元組和操作实战 Dict 字典和操作实战 作業需求 引言 这遍文章简单介绍了 Python 字符串和集合的方法和应用, ...
- python基础(八种数据类型)
Python的八种数据类型 八种数据类型分别是: number(数字).string(字符串).Boolean(布尔值).None(空值) list(列表).tuple(元组).dict(字典).se ...
- Python基础(一) - 数据类型及运算符
基本数据类型 整数(int) 浮点数(float) 字符串 以' '或" " 括起来的任意文本. a. 如果'本身也是字符,可以用" "括起来 prin ...
随机推荐
- 网站 Cookie only 唯一 防止被截获
void Page_Load(object sender, EventArgs e) { // Create a new HttpCookie. HttpCookie myHttpCookie = n ...
- CSS-单位em 和 rem
1,em单位(css3新增单位) em:就是一种长度单位,它是参照当前元素的字号,如果没有设置,就参照父容器,一直到浏览器的默认字号大小 em 是相对长度单位(参照父元素),其参照当前元素字号大小,如 ...
- Windows系统MySQL安装配置
MySQL是一个开放源代码的数据库管理系统,是由MySQL AB公司开发.发布并支持的,现在属于Oracle旗下产品. 与其他大型数据库管理系统如Oracle.DB2.SQL Server等相比,虽然 ...
- Update API
Update API可以根据提供的脚本更新文档. 该操作从索引获取文档,运行脚本(脚本语言和参数是可选的),并返回操作的结果(也允许删除或忽略该操作). 使用版本控制来确保在“get”(查询文档)和“ ...
- PDF转换成Word,ppt转换成word
pdf与word我没找到直接转换的方式,不过可以用间接方式嘛! pdf ==>picture ==>word!ppt转word的原理也是先把ppt转成图片,再把图片插入word! 先准备好 ...
- RAID部署
添加硬盘 1.创建一个RAID阵列卡 2.格式化刚刚做好的md0 3.创建挂载目录 4.自动挂载,永久生效 5.使用 创建RAID 1.创建一个RAID阵列卡 2.格式化 3.创建挂载目录 4.自动挂 ...
- sqlite3数据库教程
1.sqlite3安装(命令行): sudo apt-get install sqlite3 2.图形界面查看工具安装: sudo apt-get install sqlitebrowser 3.命令 ...
- 通过CMD将文件copy到远程电脑
net use \\192.168.1.112\ipc$ admin /user:admin #第一个admin是密码,第二admin是用户名: xcopy test.txt \\192.168.1. ...
- 仿微信的IM聊天时间显示格式(含iOS/Android/Web实现)[图文+源码]
本文为原创分享,转载请注明出处. 1.引言 即时通讯IM应用中的聊天消息时间显示是个再常见不过的需求,现在都讲究用户体验,所以时间显示再也不能像传统软件一样简单粗地暴显示成“年/月/日 时:分:秒”这 ...
- FFmpeg 结构体学习(五): AVCodec 分析
在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVFrame结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下 ...