【个人笔记】python

python-个人笔记 入门python运行 阅读详情

Title: Python学习

1 基本用法

输入输出

格式化输出

  • python的格式化输出

    str1 = "num: {}".format(123)
    str1 = "num: {:<44}".format(123)
    str1 = "num: {:^20}".format(123)
    
    • {}与.format():占位符、格式控制语句(替换{}的内容);

    • {:<44}、 {:^20}:<表左对齐、>表右对齐,数字是占位符的宽度;

      此处{:<44}表示一个宽度为44的左对齐占位符,{:^20}表示一个宽度为20的居中对齐占位符。

数组

创建

  • 创建指定大小

    # 一维
    a = [1] *10 ;		# 大小位10,初始化全1
    # 二维
    a = [ [1 for i in range(3)] for h in range(4) ]
    # 大小4行3列的二维矩阵
    # a= [ [1,1,1,], [1,1,1,], [1,1,1], [1,1,1] ]
    

添加新元素

  • 先创建空间再添加

    list = 	[1, 2, 3]
    list.append("")		# 不append直接list[4]会报IndexError
    list[4] = 4
    

    错误的方式:直接索引“尾部溢出index”来添加新元素 ❌

列表推导式

  • 英文称呼:List Comprehension

  • 语法:B = [a for a in A if a]

    • 含义:对于列表A中的每个元素a,如果a的值为真(非零、非空、非None),则将其添加到新列表中。新列表为B.
    • 优点:比普通for语句在py中运行的快。因为推导式是编译到C语言级别,而普通for语句是解释型。
    • 缺点:更耗内存。

字符串

  • 串拼接

    注意:串和数字拼接,必须手动把数字变量用str()转为字符,否则会报error。

  • 串分割

    list = str1.split(' ')可以化字符串为列表(按间隔符' ')。

文件读写

常规读/写

  • 写文件

    filename = '???'
    with open(filename, 'w') as fp:
        fp.write("...str...")
    

文件指针操作

  • file.seek(offset, 方向用法

    • 细节见此ref:文件操作中file.seek()方法
    • offset的单位:字符数(字节)
    • size = file.tell() 返回文件指针的当前位置,单位-字符数(字节)

    上述单位,不以open("xxx", 'r')还是rb为转移.

    • file.seek()的使用注意事项

      若file是以'r'打开的,则不能随意用.seek(offset数, 0/1/2),因为按字符打开的文本,其文本的编码字节与字符的内容没有一一对应的关系,用.seek()就没法精确按数量移动文件指针(除非调用.tell()函数返回offset的值),用自定义的数值进行.seek()跳转,会出现随机、未知的错误.

      我就出现了使用 file.seek(负数, 2) 的报错:io.UnsupportedOperation: can’t do nonzero end-relative seeks.

      故用.seek()函数时,最好用'rb'的二进制比特流来打开文本。

  • 从文本尾部开始读取,检索关键字

    • 文本必须以二进制流的形式读取、再用seek()函数跳转指针位置、读取比特流后得编码。

    • Demo

      with open(filename, 'rb') as file:
          file.seek(-20000, 2)
          content = file.read()
          str_content = content.decode('utf-8', errors='ignore')
          if 'fatal' in str_content:
              return 1
          else:
              return 0
      
      1. 将文件以只读、二进制的形式打卡

Python初学个人笔记(小白向)——《Learn Python the HARD WAY》   本文为初学Python的个人总结、笔记,比较小白向 (鉴于个人觉得笔记有些凌乱,建议食用指南:Ctrl+F搜着看。后期将整理) 使用书为中文书名《“笨方法”学Python》(3版), 如有错误欢迎指出:D 1.print的东西打印在一行,在print之间加"," 2.#号之后为注释内容 3.打印中文字符应该在文件头部添加:"   #_*_coding:UTF-8_*_   ";如果还... 阅读详情

相关推荐

个人笔记工具软件的Python实现

Python是1989年由Guido van Rossum发明的一种高级编程语言,以其简洁明了的语法而闻名于世。其主要特点是易于学习和阅读,具有丰富的标准库和第三方库,支持多范式编程,特别是在数据科学、人工智能等领域得到广泛应用。另外,Python是开源的,并且拥有强大的社区支持。PyQt5 是一个跨平台的 C++ 应用程序框架,使用 Python 进行绑定。它是著名的 Qt 应用程序框架的一个端口,由 Riverbank Computing 在 1998 年首先开发。

weixin_42560991的博客 1189

Python爬虫实战:微信读书笔记一键导出与个人知识库构建

数据抓取与API接口调用是网络爬虫技术的核心原理,通过模拟合法用户请求,可以高效、结构化地获取目标数据。这项技术在个人数据管理领域具有重要价值,尤其在知识管理、数据备份与迁移等场景中应用广泛。以微信读书笔记导出为例,利用Python的requests库直接请求其JSON API,能够绕过复杂的前端渲染,精准获取用户个人的划线笔记与想法评论。通过解析返回的结构化数据,并转换为Markdown等通用格式,可以实现个人阅读数据的本地化备份与知识库构建。这不仅解决了平台数据锁定的痛点,也为后续的数据关联分析、笔记软

weixin_29698641的博客 307

汇丰外包Java岗面试复盘:Zoom面1.5小时,从英语、粤语到现场敲代码的极限挑战

本文详细记录了汇丰银行外包Java岗位的面试全过程,包括多语言切换(英语、粤语)的技术沟通挑战和现场编码测试的实战经验。从高并发编程到JVM调优,面试不仅考察技术深度,更注重实战问题解决能力。文章分享了应对跨国银行技术面试的实用策略,帮助Java开发者在跨文化环境中提升竞争力。

weixin_42524824的博客 362

告别SendKeys!用DD驱动级模拟在Windows 10/11上实现真·后台键鼠操作(Python实战)

本文详细介绍了如何使用DD驱动级模拟技术在Windows 10/11上实现真后台键鼠操作,解决传统方法如pyautogui和SendKeys的局限性。通过Python实战案例,展示了驱动级模拟在游戏自动化、RPA等场景中的高效应用,包括环境配置、核心API解析及高级优化技巧。

weixin_42519985的博客 799

深度学习【46】pix2pixHD

英伟达的pix2pixHD,能够合成高清的2048*1024图片,简直振奋人心。pix2pixHD是我之前介绍过的pix2pix的改进版本,使用多由粗到精的G网络和多尺度D网络(每个D网络都是用了pix2pix中同样的patch技术)。论文一开始用pix2pix尝试合成更高分辨率的图片,但发现效果不好,训练也很不稳定。所以就对pix2pix进行了一顿魔改。我们来看看他们是怎么改进的。由粗到精的G网络

DCD_LIN的博客 1万+

强化学习-动态规划

动态规划(dynamic programming)是程序设计算法中非常重要的内容,能够高效解决一些经典问题,例如背包问题和最短路径规划。动态规划的基本思想是将待求解问题分解成若干个子问题,先求解子问题,然后从这些子问题的解得到目标问题的解。动态规划会保存已解决的子问题的答案,在求解目标问题的过程中,需要这些子问题答案时就可以直接利用,避免重复计算。本章介绍如何用动态规划的思想来求解在马尔可夫决策过程中的最优策略。

qq_45481856的博客 2113

TMS320F28377D的sys/bios双核工程配置详解——从零搭建到RAM优化

本文详细解析了TMS320F28377D双核系统在sys/bios环境下的工程配置与RAM优化策略。从开发环境搭建、SYS/BIOS工程创建到双核CMD文件配置,提供了实战技巧和常见问题解决方案,帮助开发者高效实现电力电子控制系统中的双核协作与性能优化。

weixin_28292761的博客 600

Vue Print Designer——一款让打印模板的设计变简单的可视化打印设计器

Vue Print Designer——一款让打印模板的设计变简单的可视化打印设计器

bjzhang75的博客 683

QQ也能连接OpenClaw啦!手机QQ远程操控本地AI保姆级教程

2026年最新OpenClaw与QQ连接教程发布,支持手机远程操控本地AI。腾讯官方推出QQ Bot插件,无需服务器即可实现三步绑定。教程提供三种连接方案:新手首选的扫码连接(10分钟搞定)、稳定的QQ群机器人方案,以及公网接入方案。详细步骤包括版本更新、插件安装、扫码绑定和功能测试,并附常见问题解决方案。该功能让用户通过QQ指令即可实现文件整理、文档生成等电脑操作,真正实现"手机发指令,电脑自动干"。

通俗易懂学IT 590

FineReport FCP模拟题五

新建决策报表,设置 移动端 格式,采用绝对布局。数据来源:FRDemo中的订单表/雇员表。

Davina_yu的博客 724

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: 【chips】个人笔记系列-SystemVerilog
下一篇: 【个人笔记】Git
仰天倀笑
博客等级 码龄10年 313粉丝 124原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值