1.进入python环境:

python 2:py -2

python 3:py -3

2.退出python环境 exit()/quit()/ctrl+z+enter ctrl+z+enter没有尝试成功

3.pip命令:(要在非pyhton环境下执行)

  升级命令:

    py -3 -m pip install --upgarde pip /py -3 -m pip install -u pip(pip为包名)

  安装命令:

    py -3 -m pip install nose (nose为包名)
  卸载命令:
    py -3 -m pip uninstall nose
  查看是否安装成功命令:

    py -3 -m pip show nose#非python环境下命令

    import nose#python环境下命令

  搜索命令:
    py -3 -m pip search "nose"
   列出已安装的包:
    py -3 -m pip list

4.基本的数据类型

>>> a = 1 #整型
>>> a
1
>>> type(a)
<class 'int'>
>>> type(1.2)#浮点型
<class 'float'>
>>> type("acb")#字符串
<class 'str'>

>>> type(True)# 布尔型 True和False在python里首字母必须大写 否则会报错
<class 'bool'>
>>> type(Flase)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Flase' is not defined
>>> type(False)
<class 'bool'>

>>> type([1,2,3])#列表
<class 'list'>
>>> type((1,2))#元祖
<class 'tuple'>
>>> type({1,2})
<class 'set'>
>>> type((1,2,3))
<class 'tuple'>
>>> type({'a':1,'b':3})#字典
<class 'dict'>

>>> s ={1,2}#集合
>>> type(s)
<class 'set'>
>>>

>>> dir([])/>>> dir(__builtins__)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>>

>>> help(round)#help查看某个函数的使用方法
Help on built-in function round in module builtins:
round(...)
    round(number[, ndigits]) -> number
    Round a number to a given precision in decimal digits (default 0 digits).
    This returns an int when called with one argument, otherwise the
    same type as the number. ndigits may be negative.
>>>

布尔类型的假:[]/()/{}/空字符串/False/0/none

5.运算:+,-,*,/,%,//,**

>>> 1+1
2
>>> 1-1
0
>>> 1*2
2

>>>3/2#真除

1

>>> 8//5#整取(向下取整),必反除
1

>>> 2 ** 4#幂运算
16
>>> pow(2,4)#幂运算
16

>>> import math#函数向上/下取整 先导入python自带的math

>>> math.floor(2.555)#向下取整
2
>>> math.ceil(1.2)#向上取整
2

round取整的特殊用法:

>>> round(0.5)
0

>>> round(1.5)

2

>>> round(2.5)

2

>>> round(3.5)

4

>>> help(round)#help帮助函数
Help on built-in function round in module builtins:
round(...)
    round(number[, ndigits]) -> number
    Round a number to a given precision in decimal digits (default 0 digits).
    This returns an int when called with one argument, otherwise the
    same type as the number. ndigits may be negative.
>>>
 
 
>>> divmod(7,2)
(3, 1)

divmod() 函数

说明:把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。

用法:divmod(a,b)

7//2#结果为商

7%2#结果为余数

>>> 7//2#结果为商
3
>>> 7%2#结果为余数
1

>>> import math
>>> math.pow(2,3)#次方
8.0
>>> math.sqrt(4)#开平方
2.0
>>> math.sqrt(8)
2.8284271247461903
>>> math.pi#π
3.141592653589793
>>>

 
 
>>> chr(65)
'A'
>>> chr(97)
'a'
>>> ord('a')
97
>>>
 
 
>>> for i in range(65,91):
...     print(chr(i))
...
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
>>> for i in range(65,91):
...     print(chr(i),end=' ')# end抑制换行
...
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z >>>
 
 
 
divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)
函数语法

divmod(a, b)

参数说明:

  • a: 数字
  • b: 数字

实例

>>>divmod(7, 2)
(3, 1)
>>> divmod(8, 2)
(4, 0)
>>> divmod(1+2j,1+0.5j)#python里面报错 can't take floor or mod of complex number
((1+0j), 1.5j)
 
 
作业:用chr把ASCII码所有的字母和数字打印出来
方法一:
方法二:
 
 
 
 

python学习笔记---环境的安装,pip命令,数据类型,运算的更多相关文章

  1. python学习笔记04:安装pip

    如果是从python官网下载的python版本(2.7.9或3.4)的安装包,其中已经内置了pip工具.那么只需要升级pip即可. 检测是否已安装pip: python -m pip --versio ...

  2. Python学习笔记 (2.1)标准数据类型之Number(数字)

    Python3中,数字分为四种——int,float,bool,complex int(整型) 和数学上的整数表示没啥区别,没有大小限制(多棒啊,不用写整数高精了),可正可负.还可表示16进制,以 0 ...

  3. nanopi NEO2 学习笔记 2:安装 pip 和 pip 安装第三方模块

    我现在越来越喜欢用python做开发了,特别是知道了python还能用rpi.gpio库操作 NEO2 的 io 口之后,更是激动 在进行一下的操作之前,要先更换国内的 apt arm64 源,并更新 ...

  4. python学习笔记-环境安装【1】

    1.在 WINDOWS 下面要运行命令 pip install virtualenvwrapper-win才行 参考地址http://blog.csdn.net/liuhongyue/article/ ...

  5. VS2013中Python学习笔记[环境搭建]

    前言 Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色 ...

  6. python学习笔记——git的安装及使用

    1 git的基本介绍 git 是目前世界上最先进的分布式版本哦内阁制系统 详细信息可参考廖雪峰的官方网站中的Git教程 比git功能更加强大的有TortoiseGit和Tortoise SVN,具体安 ...

  7. python学习笔记08:安装django

    linux环境安装django: sudo pip install django windows环境安装django: pip install django 验证django是否安装: python ...

  8. Python学习笔记-Linux下安装Python

    Linux系统CentOS 1.安装依赖组件 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel s ...

  9. python学习笔记--pycurl模块安装遇到的问题。

    1.用easy_install安装的时候 [root@idayuan ~]# easy_install pycurl Searching for pycurl Best match: pycurl A ...

随机推荐

  1. PythonStudy——装饰器 Decorator

    def outer(func): def inner(): print("新增功能1") func() print("新增功能2") return inner ...

  2. magento 1.9 上传后图片前后台无法正常显示

    1.上传后图片不显示,设置 允许 flash 2.保证php 执行是内存大小至少为为128M,多种方式设置,这里以init_set为例子,在index.php 加入下面一行代码,根据情况而定 ini_ ...

  3. http请求方法之options请求方法

    需预检的请求”要求必须首先使用 OPTIONS   方法发起一个预检请求到服务器,以获知服务器是否允许该实际请求. https://developer.mozilla.org/zh-CN/docs/W ...

  4. ffmpeg-4.1.1-win64-dev在vs2017的搭建

    没得话讲,先在官网下载对应的源码,下载dev/文件夹下的源码和静态链接库  ,下载/shared文件夹下的动态链接库 官网地址:https://ffmpeg.zeranoe.com/builds/wi ...

  5. Python中安装MySQL

    Windows 下Python3.6安装 mysql_python 存在各种不成功,切换到 SQLAlchemy也不行需要安装MySQL_python.需要安装mysqlclient. 执行 pip ...

  6. python各种类型日期转换大全

    最近写python做各种日期转换比较多,顺便总结一下,先上张图: # 根据字符串类型转日期 返回值类型<class 'time.struct_time'> st_time = time.s ...

  7. 在已安装64位oracle的服务器安装32位客户端

    应用场景:服务器操作系统是win2012 64位,原先安装了64位oracle12,后来系统增加导入excel的功能,网站必须启用32位兼容模式,这时候发现原有的页面打不开,提示: 试图加载格式不正确 ...

  8. __unsafe_unretained的含义

    OC的变量限定词的官方解释: __strong is the default. An object remains “alive” as long as there is a strong point ...

  9. thymeleaf的fragment例子

    fragment介绍 fragment类似于JSP的tag,在html中文件中,可以将多个地方出现的元素块用fragment包起来使用. 定义fragment 新建foot.html文件 <!D ...

  10. ES - es为什么要移除type?

    1.index.type的初衷 之前es将index.type类比于关系型数据库(例如mysql)中database.table,这么考虑的目的是“方便管理数据之间的关系”. 2.为什么现在要移除ty ...