【python3学习_1】环境和类型

【环境和类型-python3】
1.下载安装,配置环境变量,可以开始了
https://www.python.org/
https://code.visualstudio.com/
http://www.sublimetext.com/
https://www.jetbrains.com/zh/pycharm/specials/pycharm/pycharm.html
2.缩进和注释
    2.1 tab与空格不能混用
    2.2 三点为多行注释,#为单行注释
3.类型
    3.1 不需要类型声明,赋值可直接使用
    3.2 所有的变量是引用,指针的概念,i=1实际上是i指向1
    3.3 type函数可以看类型
    3.4 赋值
        3.4.1 支持多重赋值 
        3.4.2 支持多元赋值 
    3.5 运算 + - * / // % ** < <= > >= == != and or not divmod round
        支持增量赋值:+=  -=  *=  /=  %=  **=  <<=  >>=  &=  ^=  |=
        不支持自增自减运算:i++ i--
    3.6 转化 int() float() 实数-complex() str() 16进制-hex() 二进制-ord() chr() unichr()
    3.7 decimal:进行有精度的计算  
        bytes:二进制字节码类型,进行文字到字节码转化 
        math:数学函数
        random:取随机数
    3.8 type id

#--------------类型------------------
i = 12124 
print(type(i)) # int
i = 123.11
print(type(i)) # float
i = '111'
print(type(i)) # str
print(type(1 == 1)) # bool : True/False 首字母要大写
print(type(True)) 
print(type(False))

# #--------------赋值------------------
x = 1 # 实际上是x指向1
print(id(x)) # 实际指向的地址
y = 1 
print(id(y)) 

x = '123456' 
print(id(x)) 
y = '123' + '456'
print(id(y)) 

# 多元赋值-类似拆包解包概念
x = 1
x, y = 1, 2
x, y, z = 1, 2, '123'
# 多重赋值
x = y = z = 123

#--------------运算------------------
print(5 / 2) # 2.5
print(5 // 2) # 2 整除
print(5 % 2) # 1 取余
print(5 ** 2) # 25 乘方
print(5 == 5 and 5 == 3) #False 且
print(5 == 5 or 5 == 3) # True 或
print(not 5 == 3) # True 非

print(divmod(5, 3)) #(1,2) (商,余数)
print(round(5.6)) # 6 对浮点数进行近似取值,保留几位小数
# round详细解释:https://www.runoob.com/w3cnote/python-round-func-note.html

#--------------转化------------------
a = '123'
print(type(int(a))) #类型转化
print(chr(65)) # ASCII码转化

#--------------math------------------
import math

print(math.tan(math.pi/4))

#--------------random------------------
import random

#生成一个随机数
print(random.random())
#在1-100之间生成一个随机数
print(random.randint(1,108)) 

(python初学者的点滴记录,不喜勿喷)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值