一枚老猿的Python学习随笔(2)

一枚老猿的Python学习随笔(2)

本想边学习,边笔记整理,学了一天发现简单跟随一个教程太单一,随学随记吧。


PS:发现发布文章,还有markdown模板还可以,嵌入HTML,看来离开程序界太久了~~


1、学习小结

昨天在Windows10下安装了Python的开发环境,今天换了电脑,Windows7环境下安装,遇到了Server pack 1 一个升级包的问题:安装log 提示 缺少 KB2533625——ms 原有连接已经失效,着实找了一番(已上传)。

PS:Windows7 下可以选择python3.8版本


再认识Python
今天@2020.10.31
浏览了Python的简单教程,了解了:Python的数字、字符串、布尔、运算符、列表、集合、字典、数组概念、日期、Json、正则,测试了函数、Lambda,Python的分支、循环,类/对象、继承、迭代以及Python的错误处理机制,顺便试了试简单的文件读写。
总体感觉,Python语法简练,各种写法支持的很好。

接下来,研究下NumPy,NumPy就说是访问内存连续地址空间,同时硬件优化是Python内置数据处理速度的50倍,所以决定试一试。

2、安装NumPy

Python3.4开始,集成了pip(Python包管理工具)。
命令行,进入Python目录下:…\Python\Python38\ Scripts目录

C:\Users\Admin>d:
D:\>cd D:\Users\admin\AppData\Local\Programs\Python\Python38\Scripts
D:\Users\Admin\AppData\Local\Programs\Python\Python38\Scripts>pip install numpy

Python.pip

Python.NumPy
安装成功,测试是否OK:

import numpy as np #引入 NumPy 包,并重命名为 np
arr = np.array([1, 2, 3, 4, 5]) 
print(arr) # Result:[1,2,3,4,5]

Python 3.9版本有点高,改装了3.8.6!!!

3、NumPy小试

Numpy包封装了丰富的数据处理方法…


……好多好多细分功能函数...... 需要调用就好了

4、贴段代码

测试代码

import sys
import numpy as np
import matplotlib.pyplot as plt
import requests,pymongo

x = requests.get('https://w3school.com.cn/python/demopage.htm')

rtext = x.text[::-1]

print(rtext)

exec('print("a"+str(100))')

sys.exit(1)
x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22]
y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100]

mymodel = np.poly1d(np.polyfit(x, y, 3))

myline = np.linspace(1, 22, 100)

plt.scatter(x, y)
plt.plot(myline, mymodel(myline))
plt.show()

x = np.random.uniform(0.0, 5.0, 250)

plt.hist(x, 5)
plt.show()

"""
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12])
newarr = arr.reshape(24,-1)
print("arrshap:"+str(arr.shape))
print(arr)
print("=====================================")
print("newarrshap:"+str(newarr.shape))
print(newarr)
print(newarr.reshape(-1))

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.dstack((arr1, arr2))

print(arr)
"""


x = np.random.uniform(0.0, 5.0, 50001088)
print("Count:"+str(len(x)))
print(x[3333])

sys.exit(0)

print("Hello, World! ——Python")
if 5-3 == 2:
  print("YES!")

if 5 - 2== 3:
  print("NO!!")

#单行注释 
print("也可单行后半部分注释") #打印函数
"""
块注释

"""
x = y = z = 10
print(x,y,z)
x,y,z = 1,2,3
print(x,y,z)
x,y,z = 1,10,"v_x"
x +=2
z += "_var"
print(x,y,z)
print("=================")
def funcA():
    x = 100
    print(x)
funcA()
print(x)
   
x=3
print(x) 
def funcB():
    global x
    x = 100
    print(x) #result:100
funcB()
print(x) # result:100   

x,y,z = 12.5,12.80,"string"
if type(x) == int:
	int("x:"+str(type(x)))
else:
    print(type(x))

x = int(12.9)
print(x)
x = str(12.3)
print(x +"kg")

x = list(("Python", "GoLang", "Java"))
print(x)

x = 123.1
if type(x) == int:
    y = int(x)
print("sssss")

print(y)
y = 0
x = 5
if x > 10:
    y = int(x)
    y += 3
    print("A" + str(y))

if x > 10: 
	y = int(x)
y += 3
print("B" + str(y))


print(bool(-2))


class myclass():
  def __len__(self):
    return 10

myobj = myclass()
print(bool(myobj))

print(isinstance("asdf",int))

x = 1
y = 11 
print(1 in [1,2])

""" 奇怪的for循环
s =  ("a,b,c,d").split(",")
print(s)
if len(s) > 0:
    for x1 in s:
        print(x1)
        s.remove(x1)
"""
s = """
"""     
print("s:")
s = list(s)
print(s)


thisset = {"apple", "banana", "cherry"}

x = thisset.pop()

print(x)

print(thisset)

thisdict =	{
  "brand": "Porsche", 
  "brand1": "Porsche",
  "model": "911",
  "year": 1963
}
thisdict["year"] = 2019
print(thisdict)
x =8
if int(x) > 1:  print("x>1") 
print("a") if x>1 else print("b")

i = 0 
while i<=10:
    print(i)
    i +=1
else:
    print(i)
    print("else")

for x in "banana":
    print(x)
for x in range(100,201,2):
    print(x)
else:
    print("for end")

    adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]

for x in adj:
  for y in fruits:
    print(x, y)

5、研究Python的另一个原因

——今日接到多个了推广Python培训的营销电话,小学生定向营销,真是为了挣钱没有底线,孩子们能理解程序吗——或许部分天才可以,个人认为学好基础文化科才是正道。

接下来系统研究 Go Lang 开发。

补充

2020-11-23
不能白学,用Python写了数据生成:区分大小写的序列数据,运行效率还可以,谁能看出这个有啥用?

import sys
import numpy as np
from numpy import random
"""
生成 Codes 数据,数据由
62个元素[0-9,a-z,A-Z]
n位无重复组合
"""

ods = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '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', '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(ord("0"), ord("9")+1):
    ods = ods + [chr(i)]

for i in range(ord("a"), ord("z")+1):
    ods = ods + [chr(i)]

for i in range(ord("A"), ord("Z")+1):
    ods = ods + [chr(i)]
"""
ods_len = len(ods)

print("ord_len:" + str(ods_len))
print(ods)

f = open("f.dat","w")
c1=c2=c3=c4 = ""
for t1 in range(60,ods_len):
    c1 = ods[t1]
    for t2 in range(60,ods_len):
        c2 = ods[t2]
        for t3 in range(60,ods_len):
            c3 = ods[t3]
            for t4 in range(60,ods_len):
                c4 = ods[t4]
                c = c1+c2+c3+c4
                f.write(str(random.rand())+","+c+"\n")

f.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ti-蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值