目录
一、Python安装及环境搭建
二、Python运用(数据类型)
基本数据类型
引用数据类型
一、Python安装及环境搭建
Python环境安装包下载
https://www.python.org/
https://www.python.org/downloads/windows/
Python开发工具PyCharm下载
https://www.jetbrains.com.cn/en-us/
https://www.jetbrains.com.cn/en-us/pycharm/
汉化插件
#软件汉化
Chinese (Simplified) Language Pack/中文语音包
#英文翻译
Translation
安装步骤;
1.安装环境安装包
下一步->下一步安装法
最后成为后测试;
即可环境安装成功
2.安装开发软件PyCharm
点击ok
可以选择未激活试用30天,激活需要激活码
新建项目
使用汉化插件Chinese (Simplified) Language Pack/中文语音包
file->setting->plugins下载插件并且重启
二、Python运用(数据类型)
与java不同处之一 --- 数据类型
java八大数据类型:byte、short、 int 、long数字
float doble 浮点型
cahr 字符
boolean布尔
python数据类型:
int(数字)、float(浮点)、str(字符)、boolean(布尔)
基本数据类型
如int使用:
a = 2 print(type(a))
a=100
b=0x100
c=0o100
d=0b100
print(a)
print(b)
print(c)
print(d)
布尔型
#布尔型 a=True a=False print(a) # 除了none "" {} () [] Flase print((1 and 2 and 3 and 4)) print((1 and {} and 3 and 4)) print((1 and False and 3 and 4))
字符型
# 字符str方案 a="hello word!" print(type(a)) a="hello \tworld" #空格 a="hello \nworld" #还行 a="hello \"world\"" #转义 print(a)
浮点型
#精度丢失问题 import decimal a=0.6 print(type(a)) b=0.2 print(a - b) f = decimal.Decimal('0.6') g = decimal.Decimal('0.2') print(f - g)
引用数据类型
1)list集合
# python基本数据类型:
# int(数字)、
# float(浮点)
# 、str(字符)
# 、boolean(布尔)
# python注释:# “”“ ‘’‘
# a = 2
# print(type(a))
# 进制
# a=100
# b=0x100
# c=0o100
# d=0b100
# print(a)
# print(b)
# print(c)
# print(d)
# print("hhhh") #打印
#精度丢失问题
# import decimal
#
# a=0.6
# print(type(a))
# b=0.2
# print(a - b)
#
#
# f = decimal.Decimal('0.6')
# g = decimal.Decimal('0.2')
# print(f - g)
# 字符str方案
# a="hello word!"
# print(type(a))
# a="hello \tworld" #空格
# a="hello \nworld" #还行
# a="hello \"world\"" #转义
# print(a)
#布尔型
# a=True
# a=False
# print(a)
# # 除了none "" {} () [] Flase
# print((1 and 2 and 3 and 4))
# print((1 and {} and 3 and 4))
# print((1 and False and 3 and 4))
#list数组 --引用数据类型
l1=[1,2,3,4,5]
print(type(l1))
print("-------------------------------")
# 添加内容 stack栈: push放 pop拿
# 列表的定义,有值无值的分别定义方式
# pop 拿元素(删除元素)
print(l1.pop())
print("-------------------------------")
# extend 追加
l1.extend({9})
print(l1)
print("-------------------------------")
# copy 复制新的引用
l2=l1.copy()
l3=l1
print(l1)
print(l2)
print(l3)
print("-------------------------------")
# append 追加
l1.append(9)
print(l1)
print("-------------------------------")
# l1.sort() 排序
l1.sort()
print(l1)
print("-------------------------------")
# l1.sort(reverse=True) 倒序
l1.sort(reverse=True)
print(l1)
print("-------------------------------")
# remove 删除某个元素
l1.remove(1)
print(l1)
print("-------------------------------")
# insert 插入
l1.insert(2,99)
print(l1)
print("-------------------------------")
# clear 清空
# l1.clear()
# print(l1)
# print("-------------------------------")
# l1[开始:结束:步长]
print(l1[-1::-1])
print(l1[::2])
2)set集合
'''增删改查'''
# s1.clear()
# s1.copy()
# s1.remove()
# s1.pop()
# s1.add()
# 差集
a={1,2,3}
b={3,4,5}
c=a.difference(b)
d=b.difference(a)
print(c)
print(d)
print("----------------------------")
# 交集
e=a.intersection(b)
print(e)
print("----------------------------")
# 差集
print((a - b))
# 交集
print((a & b))
# 并集
print((a | b))
# 两边差集
print((a ^ b))
print("----------------------------")
# 1.公司抽奖
h={"zs","ls","ss","ww"}
black={"zs","ww"}
print(h)
print(h.pop())
# 2.黑名单用户取差集
3)dict
# 字典
p={
"name":"zs",
"age" :12
}
print(type(p))
print(p)
print(p["name"]) #打印名字内容
print(p)
p[(1,3)]="lle"
print(p)
4)元组
# 元组 ()代表元组 , {}代表set、dict ,[]代表list
a=()
print(type(a))
# 数字
b=(1)
print(type(b))
# 元组
b=(1,)
print(type(b))
#
a= input("请输入。。。")
print(a)