python基本语句学习

"""
2021/7/7
基本语句学习
"""

"""
#行话
import numpy as np#多维数组处理及分析
import matplotlib.pyplot as plt#绘图及可视化
import pandas as pd#类似R中的dataframe数据清洗等预处理操作
import seaborn as sns#
import statsmodels as sm#统计推断——回归模型、方差分析、时间序列分析、非参数方法、统计模型可视化
#scipy:积分、微分、稀疏矩阵、分布、统计检验方法等
#scikit-learn:机器学习——结果预测
#####分类:SVM、近邻、随机森林、逻辑回归等
#####回归:Lasso、岭回归等
#####聚类:K-means、谱聚类等)
#####降维:PCA(主成分分析)、特征选择、矩阵分解等
#####选型:网格搜索、交叉验证、度量
#####预处理:特征提取、标准化
"""

"""
#for语句
sequence = [1,2,None,4,None,6]
total = 0
for x in sequence:
    if x is None:
        continue#跳过序列中的None值继续求和
    total += x
print(total)
"""

"""
#for语句中的跳过和推出
t = [1,2,3,4,5,6]
to = 0
for x in t:
    if x == 5:
        break#从for语句中任何地方直接打断跳出#叠加序列直到遇到5就退出
        continue#叠加序列直到遇到5就跳过
    to += x
print(to)
"""

"""
#while语句
x = 256
total = 0
while x > 0:
    if total > 500:
        break
    total += x
    x = x//2#符号//是x除以2的值向下取整的结果
print(total)
"""

"""
#pass语句
x = int(input("Please input a int number x:"))
if x < 0:
    print("x is negative!")
elif x == 0:
    pass#只是占个位置,可稍后增加处理程序
else:
    print("x is positive!")
"""

"""
#range函数
x1 = range(10)
x2 = range(0,10)
x3 = range(0,10,1)#函数使用:range(起点,重点,步长)
x4 = list(range(0,10,1))
print(x1)
print(x2)
print(x3)
print(x4)
"""

"""
#list用法:增删改查
a = (1,2,2,3,2,2,4)#元组
b = [1,2,2,3,2,2,4]#列表
print(a.count(2))#计数并打印结果
print(type(a))
print(type(b))
b.append('app')#在列表后面增加元素
print(b)
print(type(b))
b.insert(1,'no')#在列表第二个位置b[1]处插入元素
print(b)
b.remove('app')#删掉列表中的字符元素
print(b)
b.remove(4)#删掉列表中的数字
print(b)
b.extend([7,8,(2,3)])#追加多个元素
print(b)


c = [11,1,2,23,3]
c.sort()
print(c)
#print(c.sort())返回为None,注意用法,先写程序,最后打印检查

print(sorted([7,1,2,6,0,3,2]))
print(sorted('horse race'))

print(set([1,2,2,4,3,3]))#set函数表示集合
a = set(1,2,3,4,5)
b = set(3,4,5,6,7,8)
c = set(a,b)
print(c)
#print(a|b)
"""

"""
文件操作
path = 'C:\\Users\\lenovo\\Desktop\\1970data.xlsx'
#必须要双斜杠\\才行
f = open(path,'w')#打开文件,可写,默认只可读
f.close()#关闭文件
"""



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值