<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>Eric&#039;s Blog - 编程&amp;脚本</title>
<link>https://eblog.ink/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</link>
<atom:link href="https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Fri, 09 Dec 2022 08:49:00 +0000</lastBuildDate>
<pubDate>Fri, 09 Dec 2022 08:49:00 +0000</pubDate>
<item>
<title>【Python】程序提取视频中的声音</title>
<link>https://eblog.ink/archives/325/</link>
<guid>https://eblog.ink/archives/325/</guid>
<pubDate>Fri, 09 Dec 2022 08:49:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[安装依赖pip install multiprocessingpip install moviepy.editorPython代码from multiprocessing import Pool...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>安装依赖</p><pre><code>pip install multiprocessing
pip install moviepy.editor
</code></pre><p>Python代码</p><pre><code>from multiprocessing import Pool
from moviepy.editor import AudioFileClip
import os
def p(path,path1, item):
    new_name = item.split(&#039;.&#039;)[0]+&#039;.mp3&#039;
    my_audio_clip = AudioFileClip(path+&#039;\\&#039;+item)
    my_audio_clip.write_audiofile(path1+&#039;\\&#039;+new_name)
if __name__ == &#039;__main__&#039;:
    p = input(&quot;请输入路径：&quot;)
    path = r&#039;/rooot/mp4&#039;
    path1 = path + &#039;\已处理&#039;
    os.mkdir(path1)
    list1 = [files for root, dirs, files in os.walk(path)][0]
    num_of_processes = 10
    outcome = 6
    po = Pool(num_of_processes)
    for item in list1:
        po.apply_async(p, (path,path1,item,))

    po.close()
    po.join()</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/325/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python pyPdf2&amp;amp;pyPdf 多页PDF文档处理报错</title>
<link>https://eblog.ink/archives/315/</link>
<guid>https://eblog.ink/archives/315/</guid>
<pubDate>Fri, 22 Apr 2022 09:02:30 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[当一个pdf文件有多page的时候，它将出来见你！偷笑方法是取直接修改那个文件generic.py(1)pyPdf路径大约在这里：/usr/lib/python2.7/site-packages...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>当一个pdf文件有多page的时候，它将出来见你！偷笑</p><p>方法是取直接修改那个文件generic.py</p><p>(1)pyPdf</p><p>路径大约在这里：</p><p>/usr/lib/python2.7/site-packages/pyPdf/generic.py</p><pre><code>if data.has_key(key):
      # multiple definitions of key not permitted
      raise utils.PdfReadError, &quot;multiple definitions in dictionary&quot;
data[key] = value

</code></pre><p>大约在532--536行</p><p>将它修改为：</p><pre><code>if not data.get(key):
 
    data[key] = value

</code></pre><p>（2）pyPdf2<br>路径大约在：</p><p>/usr/lib/python2.7/site-packages/PyPDF2/generic.py</p><pre><code>        if not data.get(key):
            data[key] = value
        elif pdf.strict:
            # multiple definitions of key not permitted
            raise PdfReadError(
                &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
                % (utils.hexStr(stream.tell()), key))
        else:
            warnings.warn(
                &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
                % (utils.hexStr(stream.tell()), key), PdfReadWarning)
</code></pre><p>修改为：</p><pre><code>            if not data.get(key):
                data[key] = value
#            elif pdf.strict:
#                # multiple definitions of key not permitted
#                raise PdfReadError(
#                    &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
#                    % (utils.hexStr(stream.tell()), key))
#            else:
#                warnings.warn(
#                    &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
#                    % (utils.hexStr(stream.tell()), key), PdfReadWarning)

</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/315/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>github同步仓库（非Fork）</title>
<link>https://eblog.ink/archives/278/</link>
<guid>https://eblog.ink/archives/278/</guid>
<pubDate>Thu, 27 May 2021 03:37:37 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[1.新建仓库2.点击Action3.复制复制代码修改# File: .github/workflows/repo-sync.ymlname: 自动同步on:  schedule:    - cr...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>1.新建仓库</p><p>2.点击Action</p><p>3.复制复制代码修改</p><pre><code># File: .github/workflows/repo-sync.yml
name: 自动同步
on:
  schedule:
    - cron: &#039;0 4,16  * * *&#039;
  workflow_dispatch:
  watch:
    types: started
  repository_dispatch:
    types: repo-sync
jobs:
  repo-sync:
    env:
      PAT: ${{ github.event.client_payload.PAT || secrets.PAT }} #此处PAT需要申请，教程详见：https://www.jianshu.com/p/bb82b3ad1d11
      dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 我自己同步到gitee使用，其他人可忽略
    runs-on: ubuntu-latest
    if: github.event.repository.owner.id == github.event.sender.id
    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: 开始A自动同步
        uses: repo-sync/github-sync@v2
        if: env.PAT
        with:
          source_repo: &quot;https://github.com/shuye73/MyActions.git&quot;   #此处修改
          source_branch: &quot;main&quot;
          destination_branch: &quot;main&quot;
          github_token: ${{ github.event.client_payload.PAT || secrets.PAT }}

</code></pre><p>4.申请Token<br><a href="https://github.com/settings/apps"><a href="https://github.com/settings/apps">https://github.com/settings/apps</a></a></p><p>Personal access tokens  -- Generate new token</p><p>Note 随便输入（方便辨别的）</p><p>勾选：repo  workflow</p><p>5.进入Settings--secrets 新建 New repository secret</p><p>Name 输入PAT</p><p>Value输入申请的token</p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/278/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Github  使用git将项目上传到github（最简单方法）</title>
<link>https://eblog.ink/archives/273/</link>
<guid>https://eblog.ink/archives/273/</guid>
<pubDate>Tue, 16 Mar 2021 07:41:45 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[首先你需要一个github账号，所有还没有的话先去注册吧！https://github.com/我们使用git需要先安装git工具，这里给出下载地址，下载后一路直接安装即可：https://gi...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>首先你需要一个github账号，所有还没有的话先去注册吧！</p><p><a href="https://github.com/">https://github.com/</a></p><p>我们使用git需要先安装git工具，这里给出下载地址，下载后一路直接安装即可：</p><p><a href="https://git-for-windows.github.io/">https://git-for-windows.github.io/</a></p><p>1.进入Github首页，点击New repository新建一个项目</p><p>2.填写相应信息后点击create即可 </p><p>Repository name: 仓库名称</p><p>Description(可选): 仓库描述介绍</p><p>Public, Private : 仓库权限（公开共享，私有或指定合作者）</p><p>Initialize this repository with a README: 添加一个README.md</p><p>gitignore: 不需要进行版本管理的仓库类型，对应生成文件.gitignore</p><p>license: 证书类型，对应生成文件LICENSE</p><p>3.点击Clone or dowload会出现一个地址，copy这个地址备用。</p><p>4.接下来就到本地操作了，首先右键你的项目，如果你之前安装git成功的话，右键会出现两个新选项，分别为Git Gui Here,Git Bash Here,这里我们选择Git Bash Here，进入如下界面，Test_Bluetooth即为我的项目名。</p><p>5.接下来输入如下代码（关键步骤），把github上面的仓库克隆到本地</p><pre><code>git clone https://github.com/CKTim/BlueTooth.git（https://github.com/CKTim/BlueTooth.git替换成你之前复制的地址）
</code></pre><p>6.这个步骤以后你的本地项目文件夹下面就会多出个文件夹，该文件夹名即为你github上面的项目名，如图我多出了个Test文件夹，我们把本地项目文件夹下的所有文件（除了新多出的那个文件夹不用），其余都复制到那个新多出的文件夹下，</p><p>7.接着继续输入命令 cd Test，进入Test文件夹</p><p>8.接下来依次输入以下代码即可完成其他剩余操作：</p><p><code>git add .</code>        （注：别忘记后面的.，此操作是把Test文件夹下面的文件都添加进来）</p><p><code>git commit  -m  &quot;提交信息&quot;</code>  （注：“提交信息”里面换成你需要，如“first commit”）</p><p><code>git push -u origin master</code>   （注：此操作目的是把本地仓库push到github上面，此步骤需要你输入帐号和密码）</p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/273/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>mysql 如何清除binlog</title>
<link>https://eblog.ink/archives/242/</link>
<guid>https://eblog.ink/archives/242/</guid>
<pubDate>Wed, 26 Aug 2020 09:58:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[1）：执行“reset master;”命令，该命令将删除bai所有二进制du日志，新日志的编号从“000001”开始，命令如zhi下Mysql&gt;reset master;（2）：执行“P...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>1）：<br>执行“reset master;”命令，该命令将删除bai所有二进制du日志，新日志的编号从“000001”开始，命令如zhi下</p><pre><code>Mysql&gt;reset master;
</code></pre><p>（2）：<br>执行“Purge master logs to ‘mysql-bin.<strong><em><strong>’”命令，该命令将删除“</em></strong></strong>”编号之前的所有日志，下列中删除了“mysql-bin之前编号的所有日志</p><pre><code>Mysql&gt;purge master logs to ‘mysql-bin.000015;
</code></pre><p>从结果中发现，编号000015之前的所有日志都已经删除<br>（3）：<br>执行“purge master logs before ‘yyyy-mm-dd hh24:min:ss’”命令，该命令将删除日期为“yyyy-mm-dd hh24:mi:ss”之前产生的所有日志，下列中删除了日期在“2010-05-22 01:00:之前的所有日志</p><pre><code>Mysql&gt;purge master logs before ‘ 01:00:’;
</code></pre><p>（4）：<br>设置参数—expire_logs_days=#(days)，此参数的含义是设置日志的过期天数，过来指定的天数后日志将会被自动删除，这样将有利于减少DBA管理日志的工作量。</p><pre><code>vim /etc/my.cnf

[mysqld]
--expire_logs_days=3
</code></pre><p>这样，3天前的日志都会被删除，系统自动删除</p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/242/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python pyinstaller 参数</title>
<link>https://eblog.ink/archives/314/</link>
<guid>https://eblog.ink/archives/314/</guid>
<pubDate>Tue, 16 Jul 2019 16:00:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[可选参数 说明-F dist文件夹中生成一个程序demo.exe文件，适用于一个模块没有多依赖.py文件-D 默认选项，除了主程序demo.exe外，还会在在dist文件夹中生成很多依赖文件，推...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>可选参数 说明</p><p>-F dist文件夹中生成一个程序demo.exe文件，适用于一个模块没有多依赖.py文件</p><p>-D 默认选项，除了主程序demo.exe外，还会在在dist文件夹中生成很多依赖文件，推荐使用这个</p><p>-c 默认选项，只对windows有效，使用控制台</p><p>-w 只对windows有效，不使用控制台</p><p>-p 设置导入路径</p><p>-i 给生成的demo.exe文件设置一个自定义的图标</p><p>--key 后面接加密参数</p><p><strong>使用 Pipenv减小打包文件的大小</strong></p><p>1.安装 Pipenv</p><pre><code>pip install pipenv

</code></pre><p>2.</p><pre><code>pipenv install --python 3.9
</code></pre><p>(版本为已安装的版本)</p><p>3.在命令行下激活环境</p><pre><code>pipenv shell
</code></pre><p>4.在虚拟环境下安装 Pyinstaller 和你自己的脚本依赖的第三方库</p><pre><code>pipenv install pyinstaller
pipenv install pyqt5
....
</code></pre><p>pipenv install -i <a href="https://pypi.tuna.tsinghua.edu.cn/simple">https://pypi.tuna.tsinghua.edu.cn/simple</a></p><p>5.常用指令</p><p>创建环境： pipenv install<br>激活环境： pipenv shell<br>退出环境： exit<br>删除环境： pipenv --rm</p><p>安装依赖<br>安装依赖到虚拟环境pipenv install [package]或者pip install -r requirements.txt</p><p>查看虚拟环境中的所有安装的包<br>如果没有进入虚拟环境中，则需要先使用pipenv shell进入虚拟环境。然后使用pip list查看，或者使用pip freeze &gt; requirements.txt导出所有安装的包。</p><p>删除/清空环境的依赖<br>删除指定的包：pipenv uninstall [package]<br>清空：pipenv uninstall --all或pipenv uninstall --all-dev</p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/314/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python  模式表达与正则表达式</title>
<link>https://eblog.ink/archives/207/</link>
<guid>https://eblog.ink/archives/207/</guid>
<pubDate>Tue, 16 Jul 2019 09:12:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[1.国外手机判断def iphonenum(txt):    if len(txt) != 12:        return False    for i in range(3):      ...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>1.国外手机判断</p><pre><code>def iphonenum(txt):
    if len(txt) != 12:
        return False
    for i in range(3):
        if not txt[i].isdecimal():
            return False
    if txt[3] != &#039;-&#039;:
        return False
    for j in range(4, 7):
        if not txt[j].isdecimal():
            return False
    if txt[7] != &#039;-&#039;:
        return False
    for l in range(8, 12):
        if not txt[l].isdecimal():
            return False
    return True

print(&#039;请输入手机号码：&#039;, end=&#039;&#039;)
k =input()
print(&#039;判断是否为手机号码：&#039;, iphonenum(k))
</code></pre><p>2.查找文本中的手机号码</p><pre><code>def iphonenum(txt):
    if len(txt) != 12:
        return False
    for i in range(3):
        if not txt[i].isdecimal():
            return False
    if txt[3] != &#039;-&#039;:
        return False
    for j in range(4, 7):
        if not txt[j].isdecimal():
            return False
    if txt[7] != &#039;-&#039;:
        return False
    for l in range(8, 12):
        if not txt[l].isdecimal():
            return False
    return True

mes=&#039;Call me at 415-555-1101 tomorrow.415-666-7845 is my office.&#039;
for m in range(len(mes)):
    n = mes[m:m+12]
    if iphonenum(n):
        print(&#039;找到的电话号码是：&#039;, n)
print(&#039;查找完成&#039;)</code></pre><p>3.判断国内手机号码</p><pre><code>def iphonenum(txt):
    if len(txt) != 11:
        return False
    for i in range(11):
        if not txt[i].isdecimal():
            return False
    return True

print(&#039;请输入手机号码：&#039;, end=&#039;&#039;)
k =input()
print(&#039;判断是否为手机号码：&#039;, iphonenum(k))
</code></pre><p>4.正则表达式<br>例一：</p><pre><code>import re
phonenum = re.compile(r&#039;\d\d\d-\d\d\d-\d\d\d\d&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999·&#039;
mo = phonenum.search(k)
print(&#039;打印出找到的电话号码：&#039;, mo.group())
print(mo.groups())
</code></pre><p>例二：</p><pre><code>import re
phonenum = re.compile(r&#039;(\d\d\d)-(\d\d\d-\d\d\d\d)&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999&#039;
mo = phonenum.search(k)
print(&#039;1：&#039;, mo.group())
print(&#039;2：&#039;, mo.group(1))
print(&#039;3：&#039;, mo.group(2))
print(&#039;4：&#039;, mo.groups())
j,  l = mo.groups()
print(&#039;5：&#039;, j)
print(&#039;6：&#039;, l)
m = mo.groups()
n=list(m)
print(&#039;7：&#039;, n)
o=tuple(n)
print(&#039;8：&#039;, o)
p=&#039;-&#039;.join(o)
print(&#039;9：&#039;, p)
</code></pre><p>5.用管道匹配分组</p><pre><code>import re
ph = re.compile(r&#039;Batman|Tina Fey&#039;)
a = &quot;Batman and Tina Fey&quot;
b = &quot;Tina Fey and Batman&quot;
mo1 = ph.search(a)
mo2 = ph.search(b)
print(&#039;1：&#039;, mo1.group())
print(&#039;2：&#039;, mo2.group())

phx = re.compile(r&#039;Bat(man|mil|cop|kk)&#039;)
c = &quot;Batman and Batmil and Batcop and Tina&quot;
mo3 = phx.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;4：&#039;, mo3.groups())
print(&#039;5：&#039;, mo3.group(1))
print(&#039;&#039;&#039; ////////以下是4和5转换为的列表&#039;&#039;&#039;&#039;&#039;)
d =list(mo3.groups())
print(&#039;6：&#039;,d)
e =mo3.group(1)
f = e.split()
print(&#039;7：&#039;, f)
</code></pre><p>6.问号实现可选匹配</p><pre><code>import re
px = re.compile(r&#039;Bat(wo)?man&#039;)
z = &#039;The Adventures of Batman&#039;
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo1 = px.search(z)
print(&#039;1：&#039;, mo1.group())
print(&#039;1：&#039;, mo1.groups())
print(&#039;1：&#039;, mo1.group(1))
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))</code></pre><p>7.星号实现0个或多个匹配</p><pre><code>import re
px = re.compile(r&#039;Bat(wo)*man&#039;)
z = &#039;The Adventures of Batman&#039;
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo1 = px.search(z)
print(&#039;1：&#039;, mo1.group())
print(&#039;1：&#039;, mo1.groups())
print(&#039;1：&#039;, mo1.group(1))
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
</code></pre><p>8.加号实现一个或多个匹配</p><pre><code>import re
px = re.compile(r&#039;Bat(wo)+man&#039;)
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
</code></pre><p>9.花括号实现特定次数匹配</p><pre><code>import re
px = re.compile(r&#039;Bat(wo){3,5}man&#039;)
x = &#039;The Adventures of Batwowowoman&#039;
c = &#039;The Adventures of Batwowowowoman Batman&#039;
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
print(&#039;Python正则表达式默认是贪心的，在有二义的情况匹配最长字符 &#039;)
10.findall()使用方法
import re
phonenum = re.compile(r&#039;\d\d\d-\d\d\d-\d\d\d\d&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999·411-785-1360,361-879-1360&#039;
mo = phonenum.findall(k)
for i in range(len(mo)):
    k =mo[i]
    print(&#039;打印出找到的第&#039;+str(i+1)+&#039;个电话号码：&#039;, k)
</code></pre><p>10.字符分类</p><pre><code>&#039;&#039;&#039;
\d   0-9的数字
\D   除0-9以外的数字
\w   任何数字字母或下划线字符（匹配单词字符）
\W   除字母，数字和下划线以外的任何字符
\s    空格，制表符，换行符（匹配空白字符）
\S    除空格，制表符，换行符以外的任何字符
&#039;&#039;&#039;
print(
&#039;&#039;&#039;
\d   0-9的数字
\D   除0-9以外的数字
\w   任何数字字母或下划线字符（匹配单词字符）
\W   除字母，数字和下划线以外的任何字符
\s    空格，制表符，换行符（匹配空白字符）
\S    除空格，制表符，换行符以外的任何字符
&#039;&#039;&#039;)
import re
ce =re.compile(r&#039;\d+\s+\w&#039;)
le = re.compile(r&#039;\d+\s&#039;)
qe = re.compile(r&#039;\d+&#039;)
ke=&#039;11 text,23 your,89 kill&#039;
ve =ce.findall(ke)
print(&#039;输出第一次从字符串中提取的列表：&#039;, ve)
be = &#039; &#039;.join(ve)
print(&#039;把列表转换为字符串：&#039;, be)
ne =le.findall(be)
print(&#039;输出第二次从字符串中提取的列表：&#039;, ne)
me =[]
for i in range(len(ne)):
    o =ne[i]
    p = o.strip()
    me.append(p)
print(&#039;输出去空格过后的数字列表：&#039;, me)
tuple1 = tuple(me)
print(&#039;输出转换的元组：&#039;, tuple1)
str2=&#039; &#039;.join(tuple1)
print(&#039;输出字符串：&#039;, str2)
we = qe.findall(str2)
print(&#039;再次转换为列表：&#039;, we)
ee = &#039;&#039;.join(we)
print(&#039;把所有数字链接：&#039;, ee)</code></pre><p>11.建立自己的字符分类</p><pre><code>#建立 自己的字符分类
import re
vowe =re.compile(r&#039;[aeirAidR]&#039;)
ve = &#039;Administrator,try agin&#039;
ce = vowe.findall(ve)
print(ce)
</code></pre><p>12.插入字符和美元字符</p><pre><code>import re
ne = re.compile(r&#039;\d$&#039;)
ve = re.compile(r&#039;^Hello&#039;)
ce = &#039;Hello World!&#039;
me = &quot;my number is 42&quot;
be =ne.search(me)
ae = ne.findall(me)
print(be)
print(ae)
xe = ve.search(ce)
ze= ve.findall(ce)
print(xe)
print(ze)
</code></pre><p>13.通配字符</p><pre><code>import re
me = re.compile(r&#039;.at&#039;)
ne = &#039;the cat in the hat.sat on the flat mat&#039;
be = me.findall(ne)
k =input(&#039;请加入一个以at结尾的单词：&#039;)
be.append(k)
print(be)
ve =&#039; &#039;.join(be)
ce=&#039;&#039;.join(be)
print(ve)
print(ce)
</code></pre><p>14.用点-星匹配所有字符</p><pre><code>import re
me = re.compile(r&#039;First Name:(.*) Last Name:(.*)&#039;)
ne = &#039;My First Name:Eric Last Name:Qiu&#039;
be =me.search(ne)
print(be)
print(be.group())
print(be.groups())
print(be.group(1))
print(be.group(2))</code></pre><p>15句点字符匹配换行</p><pre><code>import re
me = re.compile(r&#039;.*&#039;)
ve =re.compile(r&#039;.*&#039;, re.DOTALL)
ne = &#039;My First Name:Eric \nLast Name:Qiu&#039;
be = me.search(ne)
ce = ve.search(ne)
print(be.group())
print(ce.group())</code></pre><p>16.不区分大小写</p><pre><code>import re
me1 = re.compile(&#039;RoboCop&#039;)
me1 = re.compile(&#039;RObOCOP&#039;)
me1 = re.compile(&#039;robOcop&#039;)
me1 = re.compile(&#039;RobocOp&#039;)
ne = re.compile(r&#039;robocop&#039;, re.I)
be = &quot;RoboCop is part man.part machine,all cop&quot;
ve = ne.search(be)
print(ve.group())
</code></pre><p>17.使用sub()方法替换替换字符</p><pre><code>import re
ne = re.compile(r&#039;Agent \w+&#039;)
ve = ne.sub(&#039;CENSORED&#039;,&#039;Agent gave is part man.part machine,all cop&#039;)
print(ve)

</code></pre>
]]></content:encoded>
<slash:comments>2</slash:comments>
<comments>https://eblog.ink/archives/207/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python 字符串操作</title>
<link>https://eblog.ink/archives/205/</link>
<guid>https://eblog.ink/archives/205/</guid>
<pubDate>Thu, 11 Jul 2019 08:57:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[1.转义符\&#039;        单引号\&quot;        双引号\t        制表符\n        换行符\\        倒斜杠2.原始字符串在前面加上r例子：&...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>1.转义符</p><pre><code>\&#039;        单引号
\&quot;        双引号
\t        制表符
\n        换行符
\\        倒斜杠</code></pre><p>2.原始字符串<br>在前面加上r<br>例子：</p><pre><code>&gt;print(r&quot;my \name is Bob&quot;)
my \name is Bob
&gt;print(&quot;my \name is Bob&quot;)
my 
ame is Bob</code></pre><p>3.三重引号的多行字符串</p><pre><code>&gt;print(&#039;&#039;&#039;my
name
is
Bob
&#039;&#039;&#039;)</code></pre><p>输出的结果为：</p><pre><code>my
name
is
Bob
</code></pre><p>4，多行注释</p><pre><code>#表示这一行注释
&quot;&quot;&quot;This
is
python
&quot;&quot;&quot;

def he():
    &quot;&quot;&quot;This is 
        Python
        &quot;&quot;&quot;
    print(&#039;Hello!&#039;)
he()</code></pre><p>输出的结果为：<br>Hello!</p><p>5.字符串下标和切片</p><pre><code>&gt;spam = &#039;Hello World!&#039;
&gt;spam[0]
&#039;H&#039;
&gt;spam[0:5]
&#039;Hello&#039;</code></pre><p>6.字符串的in和not in</p><pre><code>&gt;spam = &#039;Hello World!&#039;
&gt;&#039;Hello&#039; in &#039;Hello world&#039;
True
&gt;&#039;HELLO&#039; in &#039;Hello world&#039;
False
&gt;&#039; &#039; in spam
True
&gt;&#039;cat&#039; not in spam
True</code></pre><p>7.字符串方法upper()&lower()&isupper()&islower()<br>upper()&lower()<br>字符串小大写转换，返回的也是字符串：</p><pre><code>&gt;spam = &#039;Hello&#039;
&gt;spam.upper()
&gt;print(spam)
&#039;HELLO&#039;
&gt;spam.lower()
&gt;print(spam)
hello
</code></pre><p>isupper()&islower()<br>字符串的大小写判断,返回的值为布尔值：</p><pre><code>&gt;spam = &#039;Hello&#039;
&gt;spam.isupper()
False
&gt;spam.islower()
False</code></pre><p>8.isX字符串方法<br>除上面的isupper&islower以外，还有一下</p><pre><code>isalpha()   如果字符串只包含字母，并且非空  返回True
isalnum()   如果字符串包含字母或数字，并且非空  返回True
isdecimal() 如果字符串只包含数字字符，并且非空  返回True
isspace()   如果字符串只包含空格，制表符和换行，并且非空 返回True
istitle()   如果字符串仅包含以大写字母开头，后面都是小写的单词 返回True</code></pre><p>例子：</p><pre><code>while True:
    print(&#039;请输入你的年龄: &#039;, end=&#039;&#039;)
    age=input()
    if age.isdecimal():
        break
    elif age.isalpha():
        print(&#039;&#039;&#039;
        你输入的年龄是字符!
        年龄错误!
        请再次重试.&#039;&#039;&#039;)
    elif age.isalnum():
        print(&#039;你输入的年龄包含数字和字母!请再次重试.&#039;)
    else:
        print(&#039;未知的格式！请再次重试&#039;)
print(&#039;你的年龄是：&#039;+age)
</code></pre><p>9.startswith()&endswith()的使用方法<br>验证开头和结尾是否为对应的值，返回的也是布尔值：</p><pre><code>&gt;spam = &#039;Hello World!&#039;
&gt;spam.startswith(&#039;Hello&#039;)
True
&gt;spam.endswith(&#039;World!&#039;)
True
&gt;spam.endswith(&#039;Hello&#039;)
False</code></pre><p>10.join()和split()的使用方法<br>join()使列表通过某一个字符分开变为字符串<br>例子：</p><pre><code>spam = [&#039;my&#039;, &#039;name&#039;, &#039;is&#039;, &#039;Eric&#039;]
k =&#039; &#039;.join(spam)
print(k)</code></pre><p>输出的结果为</p><pre><code>my name is Eric</code></pre><p>split()使字符串通过某一字符分开变为列表<br>例子：</p><pre><code>spam = &#039;my name is Eric&#039;
j =spam.split()
print(j)</code></pre><p>输出的结果为</p><pre><code>[&#039;my&#039;, &#039;name&#039;, &#039;is&#039;, &#039;Eric&#039;]</code></pre><p>10.rjust()&ljust()&center()对齐的使用</p><pre><code>spam = &#039;my name is Eric&#039;
k = spam.rjust(30)
print(&#039;输出k的值（右对齐30个字符）：&#039;, k)
j = spam.ljust(30)
print(&#039;输出j的值（左对齐30个字符）：&#039;, j)
i = spam.center(30)
print(&#039;输出i的值（居中对齐30个字符）：&#039;,i)
k = spam.rjust(30, &#039;#&#039;)
print(&#039;输出k的值（右对齐30个字符）：&#039;, k)
j = spam.ljust(30, &#039;*&#039;)
print(&#039;输出j的值（左对齐30个字符）：&#039;, j)
i = spam.center(30, &#039;-&#039;)
print(&#039;输出i的值（居中对齐30个字符）：&#039;,i)</code></pre><p>11.strip()&rstrip()&lstrip()去除空格使用</p><pre><code>spam = &#039; Hello World! &#039;
i = spam.strip()
print(&#039;使用strip()后的值：&#039;)
print(i)
j = spam.rstrip()
print(&#039;使用rstrip()后的值：&#039;)
print(j)
k = spam.lstrip()
print(&#039;使用lstrip()后的值：&#039;)
print(k)</code></pre><p>12.pyperclip模块复制粘贴字符串</p><pre><code>#使用前确保已经安装pyperclip模块
import pyperclip
spam = &#039; Hello World! &#039;
pyperclip.copy(spam)
print(pyperclip.paste())
</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/205/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python 字典</title>
<link>https://eblog.ink/archives/204/</link>
<guid>https://eblog.ink/archives/204/</guid>
<pubDate>Thu, 11 Jul 2019 08:32:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[1.字典和数据类型mycat ={&#039;size&#039;:&#039;fat&#039;, &#039;name&#039;:&#039;Vice&#039;, &#039;color...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>1.字典和数据类型</p><pre><code>mycat ={&#039;size&#039;:&#039;fat&#039;, &#039;name&#039;:&#039;Vice&#039;, &#039;color&#039;:&#039;gray&#039;}
print(&quot;输出猫的名字为：&quot;, mycat[&#039;name&#039;])
print(&#039;my cat name is &#039;+mycat[&#039;name&#039;])
</code></pre><p>2.字典与列表</p><pre><code>spam=[&#039;dogs&#039;,&#039;cat&#039;,&#039;pig&#039;]
bacon = [&#039;pig&#039;,&#039;cat&#039;,&#039;dogs&#039;]
print(&quot;spam=[&#039;dogs&#039;,&#039;cat&#039;,&#039;pig&#039;]&quot;)
print(&quot;bacon = [&#039;pig&#039;,&#039;cat&#039;,&#039;dogs&#039;]&quot;)
if spam == bacon:
    print(&quot;True&quot;)
else:
    print(&#039;False&#039;)
    
egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
ham = {&#039;color&#039;:&#039;gray&#039;, &#039;name&#039;:&#039;jim&#039;}
print(&quot;egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}&quot;)
print(&quot;ham = {&#039;color&#039;:&#039;gray&#039;, &#039;name&#039;:&#039;jim&#039;}&quot;)
if egg == ham:
    print(&#039;True&#039;)
else:
    print(&#039;False&#039;)
while True:
    print(&#039;请输入egg中的值：&#039;,end=&#039; &#039;)
    k = input()
    try:
        print(egg[k])
        break
    except KeyError:
        print(&#039;输入的字典中没有&#039;)
</code></pre><p>3.keys()&values&items()使用方法</p><pre><code>egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
for v in egg.values():
    print(&quot;打印出值：&quot;, v)
    
print(&quot;\n&quot;)
for k in egg.keys():
    print(&quot;打印出键：&quot;, k)
print(&quot;\n&quot;)

for i in egg.items():
    print(&quot;打印出键-值：&quot;, i)
    
</code></pre><p>4.检查字典中的键或值</p><pre><code>egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
&quot;name&quot; in egg.keys()
&#039;gray&#039; in egg.values()
</code></pre><p>5.get()使用</p><pre><code>spam={&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
print(&#039;获取Name的值：&#039;, spam.get(&#039;name&#039;, 0))
print(&#039;输入需要查找的键：&#039;, end=&#039; &#039;)
j = input()
k =spam.get(j, 0)
if k == 0:
    print(&#039;字典中没有&#039;+str(j)+&#039;的值&#039;)
else:
    print(&#039;键&#039;+str(j)+&#039;的值为：&#039;, k)
</code></pre><p>6.setdefault()使用：<br>1：</p><pre><code>spam={&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
while True:
    print(&#039;输入需要查找的键：&#039;, end=&#039; &#039;)
    j = input()
    k =spam.get(j, 0)
    if k == 0:
        print(&#039;字典中没有&#039;+str(j)+&#039;的值&#039;)
        print(&#039;输入&#039;+str(j)+&#039;的值：&#039;, end=&#039;&#039;)
        i =input()
        spam.setdefault(j, i)
        print(&#039;输出字典spam：&#039;, spam)
    else:
        print(&#039;键&#039;+str(j)+&#039;的值为：&#039;, k)
        break
</code></pre><p>2：</p><pre><code>message = &quot;John Smith was a good math student at a high school. He loved his computer. He came home early every day. Then he worked with it till midnight. But John was not a good English student, not good at all. He got an F in his English class. One day after school, John joined his computer to the computer in his high school office. The school office computer had the grades of all the students: the math grades, the science grades, the grades in arts and music, and grades in English. He found his English grade. An F! John changed his English grade from F to A. John’s parents looked at his report card. They were very happy. &quot;
count={}
for char in message:
    count.setdefault(char, 0)
    count[char] = count[char]+1
print(count)
</code></pre><p>7.漂亮的打印pprint</p><pre><code>import pprint
v = &quot;John Smith was a good math student at a high school. He loved his computer. He came home early every day. Then he worked with it till midnight. But John was not a good English student, not good at all. He got an F in his English class. One day after school, John joined his computer to the computer in his high school office. The school office computer had the grades of all the students: the math grades, the science grades, the grades in arts and music, and grades in English. He found his English grade. An F! John changed his English grade from F to A. John’s parents looked at his report card. They were very happy. &quot;
count={}
for char in v:
    count.setdefault(char, 0)
    count[char] = count[char]+1
pprint.pprint(count)
</code></pre><p>8.#字棋</p><pre><code>the = {&#039;top-L&#039;:&#039;&#039;,&#039;top-M&#039;:&#039; &#039;,&#039;top-R&#039;:&#039; &#039;,
&#039;mid-L&#039;:&#039; &#039;,&#039;mid-M&#039;:&#039;&#039;,&#039;mid-R&#039;:&#039; &#039;,
&#039;low-L&#039;:&#039; &#039;,&#039;low-M&#039;:&#039; &#039;,&#039;low-R&#039;:&#039;&#039;}
print(the)

def bord(eh):
    print(eh[&#039;top-L&#039;]+&#039;|&#039;+eh[&#039;top-M&#039;]+&#039;|&#039;+eh[&#039;top-R&#039;])
    print(&#039;-+-+-&#039;)
    print(eh[&#039;mid-L&#039;]+&#039;|&#039;+eh[&#039;mid-M&#039;]+&#039;|&#039;+eh[&#039;mid-R&#039;])
    print(&#039;-+-+-&#039;)
    print(eh[&#039;low-L&#039;]+&#039;|&#039;+eh[&#039;low-M&#039;]+&#039;|&#039;+eh[&#039;low-R&#039;])
turn = &quot;X&quot;
for i in range(9):
    bord(the)
    print(&#039;Turn for &#039; + turn+&#039; . Move on which space?&#039;)
    move =input()
    the[move]= turn
    if turn == &#039;X&#039;:
        turn = &quot;O&quot;
    else:
        turn = &quot;X&quot;
bord(the)
</code></pre><p>9.嵌套字典列表</p><pre><code>the = {&#039;Alice&#039;:{&#039;apples&#039;:5, &#039;pies&#039;:12}, 
&#039;Bob&#039;:{&#039;cup&#039;:3, &#039;apples&#039;:2}, 
&#039;Jim&#039;:{&#039;cup&#039;:6, &#039;pies&#039;:7}
}

def  tho(guess, item):
    num = 0
    for k, v in the.items():
        num += v.get(item, 0)
        print(&#039;k的值:&#039;, k)
        print(&quot;v的值:&quot;, v)
    return num

print(&#039;Number of things being brought:&#039;)
print(&#039;- apples &#039;+str(tho(the, &#039;apples&#039;)))
print(&#039;- cup &#039; +str(tho(the, &#039;cup&#039;)))
print(&#039;- pies &#039;+str(tho(the, &#039;pies&#039;)))

</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/204/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
<item>
<title>Python 列表</title>
<link>https://eblog.ink/archives/203/</link>
<guid>https://eblog.ink/archives/203/</guid>
<pubDate>Wed, 10 Jul 2019 02:18:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[列表应用例子：1.打印出家里所有猫的名字catname=[]while True:    print(&quot;输入第&quot;+str(len(catname)+1)+&#039;只猫的名...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>列表应用例子：<br>1.打印出家里所有猫的名字</p><pre><code>catname=[]
while True:
    print(&quot;输入第&quot;+str(len(catname)+1)+&#039;只猫的名字&#039;+&#039;(或者不输入直接回车结束.)：&#039;)
    name = input()
    if name == &quot;&quot;:
        break
    catname = catname+[name]
print(&quot;The cat names are：&quot; ,name)
i=0
for name in catname:
    i+=1
    print(&#039;第&#039;+str(i) +&quot;只猫的名字是：&quot;+name)
</code></pre><p>2.用循环列表打印出：</p><pre><code>for i in [1,2,3,4,5]:
    print(i)
</code></pre><p>3.列表中in的使用</p><pre><code>spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
while True:
    print(&#039;输入字母：&#039;)
    name = input()
    if name in spam:
        print(&quot;你输入的字母在列表中为：&quot;,name)
        break
    else:
        print(&#039;你输入的字母不在列表中。&#039;)
</code></pre><p>4.列表中not in的使用</p><pre><code>spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
i=0
while True:
    i+=1
    print(&#039;输入字母：&#039;)
    name = input()
    if name not in spam:
        print(&#039;你输入的字母不在列表中&#039;)
        continue
    else:
        print(&#039;你输入的字母在列表中为：&#039;,name)
        break
print(&#039;您使用了&#039;+str(i)+&#039;次猜中了列表中数字&#039;)
</code></pre><p>5.增强赋值</p><pre><code>for i in range(5):
    i +=1
    print(i)
    k=7
    k -=1
    print(k)
    j =2
    j +=1
    j*=2
    print(j)
    l=10
    l +=1
    l /=2
    print(l)
    m=15
    m +=1
    m%=2
    print(m)
    print(&#039;\n&#039;)
</code></pre><p>6.列表中index查找索引位置</p><pre><code>spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
for i in range(1, 7):
    print(&#039;输入26个字母中的1个：&#039;)
    mu = input()
    if mu in spam:
        print(&#039;您输入的&#039;+mu+&#039;在列表中的&#039;+str(spam.index(mu)+1)+&quot;位置&quot;)
        break
    else:
        print(&quot;您输入的字母不在列表中&quot;)
if 0&lt;i&lt;6:
    print(&#039;您使用了&#039;+str(i)+&#039;次机会&#039;)
else:
    print(&#039;您的6次机会已使用完&#039;)
</code></pre><p>7.列表append添加值</p><pre><code>spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
for i in range(len(spam)):
    print(&#039;请输入第&#039;+str(i+1)+&#039;次需要添加的字母：&#039;,end=&#039; &#039;)
    mu = input()
    if mu != &quot;j&quot;:
        spam.append(mu)
    elif mu == &#039;j&#039;:
        print(&#039;输入了错误的J&#039;)
        break
print(spam)
</code></pre><p>8.insert指定位置插入</p><pre><code>import random
spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
i = 1
while True:
    if i &lt; 11:
        k = random.randint(0,4)
        print(&quot;输出第&quot;+str(i)+&quot;次k的值：&quot;,k)
        mu = input(&#039;请输入需要添加的字母：&#039;)
        spam.insert(k,mu)
        
    else:
        break
    i +=1
print(&quot;打印出现在的spam：&quot;,spam)

9.remove()删除列表中的元素
spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;,&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;,&#039;a&#039;]
print(&quot;打印出现在的spam值：&quot;,spam)
for i in range(10):
    k=input(&#039;请输入需要删除的abcd中的一个字母&#039;)
    try:
        spam.remove(k)
        print(&quot;打印出删除过后的spam的值：&quot;,spam)
    except ValueError:
        print(&#039;列表中没有该元素了。&#039;,spam)
</code></pre><p>10.sort对列表排序</p><pre><code>spam = []
for i in range(7):
    print(&#039;请给列表添加数字：&#039;,end=&#039;&#039;)
    j = int(input())
    if j != 99:
        spam.append(j)
    elif j == 99:
        print(&#039;输入了错误的数字：99&#039;)
        break
try:
    print(&quot;打印出已知的列表&quot;,spam)
    spam.sort(reverse=False)
    print(&#039;输出升序值&#039;,spam)
    spam.sort(reverse=True)
    print(&#039;输入降序值&#039;,spam)
except TypeError:
    print(&quot;你的列表是数字和字母混合，不能排序&quot;)
</code></pre><p>11.可变和不可变的数据类型</p><pre><code>name = &#039;Zophie a cat&#039;
print(&#039;输出name：&#039;,name)
newname =name[0:7]+&#039;the&#039;+name[8:12]
print(&quot;newname =name[0:7]+&#039;the&#039;+name[8:12]&quot;)
print(&#039;输出newname：&#039;,newname)

print(&#039;改变id&#039;)
eggs=[1,2,3]
print(id(eggs))
eggs=[4,5,6]
print(id(eggs))

print(&#039;不改变id&#039;)
egg=[1,2,3]
print(id(egg))
del egg[2]
del egg[1]
del egg[0]
egg.append(4)
egg.append(5)
egg.append(6)
print(id(egg))
</code></pre><p>12.元组数据类型</p><pre><code>eggs = (&#039;hello&#039;,42,0.5)
print(&#039;输出eggs[ 0]：&#039;,eggs[0])
print(&#039;输出eggs[1:3]：&#039;,eggs[1:3])
print(&#039;计算eggs的长度：&#039;,len(eggs))
13.list,tuple数据类型的相互转换
tuple1=(1,2,4,6)
list1 =[4,5,6,7]

print(&#039;打印转换前的tuple1：&#039;,tuple1)
print(&#039;打印转换后的tuple1：&#039;,list(tuple1))
print(&#039;打印转换前的list1：&#039;,list1)
print(&#039;打印转换前的list1：&#039;,tuple(list1))
</code></pre><p>14.引用</p><pre><code>s = 42
while True:
    c=s
    s = 100
    print(&quot;输出s：&quot;,s,id(s))
    print(&quot;输出c：&quot;,c,id(c))
    break

sp = [0,1,2,3,4]
che =sp

print(&#039;sp的值为：&#039;,sp)
print(&#039;che的值为：&#039;,che)
while True:
    print(&#039;输入判断值0或者1：&#039;,end=&#039; &#039;)
    j = int(input())
    if j == 0:
        k =input(&#039;输出需要改变的值：&#039;)
        che[0]=k
        print(&#039;输出修改che[0]后che的值：&#039;,che,id(che))
        print(&#039;输出修改che[0]后sp的值：&#039;,sp,id(sp))
        break
    elif j == 1:
        k =input(&#039;输出需要改变的值：&#039;)
        sp[0]=k
        print(&#039;输出修改che[0]后che的值：&#039;,che,id(che))
        print(&#039;输出修改che[0]后sp的值：&#039;,sp,id(sp))
        break
    else:
        print(&#039;请输入0或者1&#039;)
        continue
</code></pre><p>15.传递引用</p><pre><code>def egg(some):
    some.append(&#039;hello&#039;)
spam = [1,2,3,4]
egg(spam)
print(spam)
</code></pre><p>16.copy模块</p><pre><code>import copy
spam= [1,&#039;A&#039;,3,4,5]
cheese = copy.copy(spam)
cheese[1] = 2
print(&#039;输出spam的列表和ID：&#039;,spam,id(spam))
print(&#039;输出cheese的列表和ID：&#039;,cheese,id(cheese))



</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/203/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</wfw:commentRss>
</item>
</channel>
</rss>