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

abs()

int(x)

x converted to integer

int()

float(x)

x converted to floating point

float()

complex(re, im)

a complex number with real part re, imaginary part im. im defaults to zero.

complex()

c.conjugate()

conjugate of the complex number c

divmod(x, y)

the pair (x // y, x % y)

divmod()

pow(x, y)

x to the power y

pow()

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、数据类型的更多相关文章

  1. python基础之五大标准数据类型

    学习一门语言,往往都是从Hello World开始. 但是笔者认为,在一个黑框框中输出一个"你好,世界"并没有什么了不起,要看透事物的本质,熟悉一门语言,就要了解其底层,就是我们常 ...

  2. python基础及安装

    一.python介绍 介绍  python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,Guido开始写能够解释Python语言语法的解释器.Python这个名 ...

  3. 【Python基础】安装python第三方库

    pip命令行安装(推荐) 打开cmd命令行 安装需要的第三方库如:pip install numpy 在安装python的相关模块和库时,我们一般使用“pip install  模块名”或者“pyth ...

  4. Python基础之模块、数据类型及数据类型转换

    一.模块 1.标准库 不需要安装,直接调入使用的模块. import sys模块: import sys print(sys.path) #打印环境变量绝对路径 print(sys.argv) #打印 ...

  5. python基础(二)-------数据类型

    python开发基础篇(二)数据类型 python数据类型有: 1.数字 1.只能存放一个值 2.一经定义,不可更改 3.直接访问 主要的分类为:整型,长整型,(python2有长整型的概念Pytho ...

  6. python基础-第二篇-基本数据类型

    一.运算符 1.算数运算: 算数运算符相信大家都不陌生吧,尤其是加减乘除,好!那我就带着大家看看最后三个,这三个到底是干什么玩意的? %,取两数相除的余数,看图: **,x的多少次幂,看图: //,取 ...

  7. Python基础语法,基本数据类型及相关操作

    ---恢复内容开始--- python文件 文件开头要有  #!/usr/bin/ python        --在linux中是告诉系统phthon的路径是在/usr/bin/ python目录下 ...

  8. 第二章:Python基础の快速认识基本数据类型和操作实战

    本课主题 字符串和操作实战 二进制操作实战 List 列表和操作实战 Tuple 元組和操作实战 Dict 字典和操作实战 作業需求 引言 这遍文章简单介绍了 Python 字符串和集合的方法和应用, ...

  9. python基础(八种数据类型)

    Python的八种数据类型 八种数据类型分别是: number(数字).string(字符串).Boolean(布尔值).None(空值) list(列表).tuple(元组).dict(字典).se ...

  10. Python基础(一) - 数据类型及运算符

    基本数据类型 整数(int) 浮点数(float) 字符串 以' '或" " 括起来的任意文本.  a. 如果'本身也是字符,可以用" "括起来    prin ...

随机推荐

  1. antd-mobile less文件用模块方式引入

      config-overrides.js文件修改::::: const { injectBabelPlugin, getLoader } = require('react-app-rewired') ...

  2. ubuntu显卡驱动安装

    1.确定显卡型号 网上有些使用lspci | grep -i nvidia可以查看显卡型号,但是我的好像查不到具体型号,如下图. 但是后来我知道了安装的是1080Ti,所以也就明确了型号.驱动在(ht ...

  3. 2003server r2 + sql 2000 sp4 环境配置

    由于工作需求需要配置一个windows 2003 server r2 + sql 2000 sp4的环境: 一.2003server准备系统: msdn 下载 分清x86还是x64 一共有两个cd准备 ...

  4. 初次接触之R语言

    一.什么是R? 最受欢迎的数据分析和可视化平台之一. 其他分析平台:Excel.SPSS.SAS 二.为什么选择R? 免费.支持WINDOWS/MAC OS/Linux. 开源

  5. 将字符串XX,SS以“,”符号进行区分并分别存储在数组中

    public static void main(String[] args) { String str = "EAN_13,1534651"; String strs[] = st ...

  6. Python实现实现基于最小二乘法的线性回归

    下面展示利用Python实现基于最小二乘法的线性回归模型,同时不需要引入其他科学计算以及机器学习的库. 利用Python代码表示如下: #首先引入数据集x,和y的值的大小利用Python的数据结构:列 ...

  7. java常使用的框架

    一.SpringMVC Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动 ...

  8. input type=passoord 密码框的明密文(显示和隐藏) 显示

    最近在写一个新的项目,从头开始写,所以就要从注册登录开始做起.以前写登录注册模块的时候,无外乎给input框一个type=”password”就可以了,近期因为要涉及到显示隐藏状态的切换. 样式代码如 ...

  9. 平衡二叉树(AVL)介绍及其实现

    一.平衡二叉树 任何一个数据的查找过程都需要从根结点出发,沿某一个路径朝叶子结点前进.因此查找中数据比较次数与树的形态密切相关. 对于二叉树来说,当树中每个结点左右子树高度大致相同时,树高为logN. ...

  10. [Swift]LeetCode407. 接雨水 II | Trapping Rain Water II

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...