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 ...
随机推荐
- Eclipse自动补全调教
方法来自http://www.cnblogs.com/sunjie21/archive/2012/06/28/2567463.html 调教后可以做到: 1. sout + Tab 输出System. ...
- vue font-icon 图标
1.vue 游览器左上角小图标 把.ico文件放在根目录下的static文件夹下,然后link标签引入 <link rel="shortcut icon" href=&quo ...
- php代码进行跨域请求处理
以下的函数作为每个请求的前置操作 (thinkphp框架) public function appInit(&$params) { header('Access-Control-Allow-O ...
- Django+wechatpy接入微信公众平台以及授权登录
确定Django环境可以正常运行,环境搭建见:Linux 搭建Nginx+uwsgi+Django环境 安装 wechatpy[cryptography] sudo pip3 install wech ...
- mysql5.7忽略大小写问题
mysql5.7忽略大小写问题 1.1 前言 新安装mysql5.7版本后,linux环境下默认是大小写敏感的. 1.2 忽略大小写敏感步骤 进入mysql配置文件: vi /et ...
- .NET 应用架构电子书中文版
<.NET 微服务:容器化 .NET 应用架构指南> 本书主要介绍了基于容器和微服务的应用架构和设计原则,以及基于 .NET Core 和 Docker 容器的应用程序开发实践.为了让大家 ...
- freekan5.9电影网站安装及源码分享
Freekan是一套目前非常火的电影网站系统,全自动采集,支持对接公众号 服务器环境:centos7,宝塔面板,php7.1(重要),nignx,mysql 1.首先上传压缩包到网站目录,然后解压 2 ...
- numpy.random 常用函数详解之排列乱序篇(Permutations)
1.numpy.random.shuffle(x) 参数:填入数组或列表. 返回值:无. 函数功能描述:对填入的数组或列表进行乱序处理,shape保持不变. 2.numpy.random.permut ...
- [Bash]LeetCode194. 转置文件 | Transpose File
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- [Swift]LeetCode1021. 删除最外层的括号 | Remove Outermost Parentheses
A valid parentheses string is either empty (""), "(" + A + ")", or A + ...