Python 个人笔记

该博客是 Python 学习笔记,涵盖基础数据类型、复合数据类型、运算符、格式化字符串等基础知识,还介绍了函数定义、面向对象编程、模块导入等内容,涉及 os、time、json 等多个内置模块及 requests、pandas 等常用模块。

Python 笔记

  • hello world
print("hello world!")
  • print 换行符
print('hello \n world')
  • print 行结束符
print('hello \n world', end='?')
  • 基础数据类型
a = 6
b = 1.34
c = True
d = 'hello world'
  • 变量命名规范

    1. 数字 字母 下划线

    2. 不能以数字开头

    3. 不能使用保留字

    4. 严格区分大小写

      保留字
      fromimortas
      TrueFalseNone
      classpasswith
      defyieldretrun
      ifelifelse
      forwhilecontinuebreak
      tryraiseexceptassertfinally
      isnotinandor
      labmdadelglobalnonlocal
  • 复合数据类型

list 列表

ls = [6, 1.34, True, 'alex']

tuple 元组

tl = [6, 1.34, True, 'alex']

dict 字典

dl = [6, 1.34, True, 'alex']

set 集合

st = [6, 1.34, True, 'alex']
  • 运算符

  • 格式化字符串

    python 3.6 以后支持 f-string format的简化版本

    print(f'name is {name}, age is {age}, alex age is {sta.age}')
    print(f'get {12*3+5}')
    print(F"name is {name:#<6s}, age is {age:3d}, weight is {weight:^9.2f}")
    print(F"name is {'davida':#<6s}, age is {111:3d}, weight is {123456.789:9.2f}")
    print(f'hex value {254:#X}')

    format 方式

    print('name is {:6s} next'.format(name))
    print('name is {:.3s}'.format(name))
    print('age is {:0>6d}'.format(age))
    print('age is {:0<6d}'.format(age))
    print('age is {:\>6d}'.format(age))
    print('age is {:6d}'.format(age + 111))  # 默认是右对齐
    # print('age is {:>6d} next'.format(age+1))
    print('age is {:<6d} next'.format(age + 1))
    print('age is {:^6d} next'.format(age + 1))
    print('weight is {:+12.3f}'.format(weight))
    print('weight is {:.2%}'.format(weight / 120))
    print('id is {:6d}'.format(id))
    print('\n\n')
    
    print('name is {}, age is {}'.format(name, age))
    print('name is {0}, age is {1}, name is {0}'.format(name, age))
    info_list = [name, age]
    print('name is {0[0]}, age is {0[1]}, name is {0[0]}'.format(info_list))
    
    print('name is {name}, age is {age}, name is {name}'.format(name=name, age=age))
    info_dict = {'name': name, 'age': age}
    print('name is {name:?>12s}, age is {age}, name is {name}'.format(**info_dict))
    
    class Student(object):
        def __init__(self, name, age):
            self.name = name
            self.age = age
    
    sta = Student('alex', 12)
    stb = Student('lucy', 11)
    print('alex name is {0.name}, lucy age is {1.age}'.format(sta, stb))

    % 方式: 变量和占位符一一对应,不够灵活

    print('age is %d' % age)
    print('age is %6d' % age)
    print('age is %11d' % age)
    print('age is %06d' % age)
    print('age is %011d' % age)
    
    print('name is %s' % name)
    print('name is %24s' % name)
    print('name is %.3s' % name)
    print('name is %a' % name)
    
    print('weight is %f' % weight)
    print('weight is %.2f' % weight)
    # %6.2f 表示总长度为6(包括小数点),保留2位小数
    print('weight is %6.2f' % weight)
    
    print('MULTI: name is %s, age is %d' % (name, age))
    print('MULTI: name is %s, age is %s' % (name, age))
  • 转义字符

  • 基础数据类型转换

  • 复合数据类型转换 容器

  • 字符串编码

  • 赋值与引用的概念

  • 运算符重载/公共操作

  • 内置函数 基础

  • print详解

  • if

  • for

  • while

  • def 函数定义

  • def 参数

  • def 函数说明信息

  • lambda

  • 内置函数 高阶

  • 文件操作 open

  • 面向对象 class

  • 导入模块 from import as

  • 内置模块 os

  • 内置模块 time

  • 内置模块 random

  • 内置模块 json

  • 内置模块 request

  • 内置模块 urllib

  • 列表推导式

  • 字典推导式

  • 集合推导式

  • 常用模块 requests

  • 常用模块 pandas

  • 常用模块 pathlib

转载于:https://www.cnblogs.com/alex-zen/p/11157392.html

<think>好的,我现在需要帮助用户找到使用Python开发个人笔记本应用的相关信息或教程。首先,我需要明确用户的需求。他们提到的“个人笔记本应用”可能是指类似于Evernote或OneNote的笔记管理应用,或者是使用Python笔记本(比如JupyterNotebook)上进行开发。不过结合引用内容,用户之前提到过Jupyter Notebook,可能是指后者。但根据用户当前的问题,“开发个人笔记本应用”更可能是指创建一个笔记管理软件。接下来,我需要参考用户提供的引用。引用[2]提到JupyterNotebook是一个交互式笔记本,可以运行Python代码,显示结果,并且有很多教程案例。引用[4]讨论了Python编程笔记本的配置,推荐了一些硬件。引用[5]涉及使用Python开发鸿蒙应用,但可能与当前问题关联不大。用户的需求可能是学习如何用Python构建一个本地的笔记应用程序,用于记录和管理个人笔记。因此,我需要提供相关的开发框架、库以及教程步骤。 首先,确定技术栈。Python有几个GUI库,如Tkinter(内置)、PyQt、Kivy等。数据库方面可以使用SQLite或本地文件存储。推荐Tkinter,因为它是标准库,适合初学者。对于更复杂的界面,PyQt可能更好,但需要安装。然后,分解开发步骤:设计界面、实现笔记的增删改查、添加数据存储功能。需要引用相关库,比如Tkinter和SQLite3。引用中提到的Jupyter Notebook可能用于代码编写和测试,但开发桌面应用更多需要IDE或文本编辑器。引用[4]推荐的笔记本配置可能对用户有帮助,但用户的问题更偏向软件开发而非硬件选择。 需要确保回答结构清晰,分步骤说明,并提供示例代码。同时生成相关问题,如优化方法、数据同步等。最后检查是否符合系统级指令:使用正确LaTeX格式,中文回答,引用标识。例如,在提到数学公式时使用$...$,独立公式用$$...$$,但当前问题可能不涉及数学公式,但需要留意。不过用户的问题主要关于开发应用,可能不需要数学表达式,但需确保其他指令如引用正确。总结回答结构:概述技术选型,分步骤教程,代码示例,推荐工具,相关资源,最后生成问题。</think>### 使用Python开发个人笔记本应用的教程 开发个人笔记本应用主要涉及**界面设计**、**数据存储**和**功能逻辑实现**。以下是分步骤指南: --- #### 一、技术选型 1. **GUI框架**: - **Tkinter**:Python内置库,适合快速开发简单界面[^2] - **PyQt/PySide**:功能强大,支持复杂界面设计[^4] 2. **数据存储**: - **SQLite**:轻量级数据库,无需额外配置 - **本地文件存储**:使用JSON或CSV格式保存笔记 --- #### 二、开发步骤(以Tkinter为例) **1. 界面设计** ```python import tkinter as tk from tkinter import ttk class NotebookApp: def __init__(self, root): self.root = root self.root.title("个人笔记本") # 笔记列表 self.note_list = ttk.Treeview(self.root, columns=("标题", "时间")) self.note_list.pack(side="left", fill="y") # 编辑区域 self.text_edit = tk.Text(self.root) self.text_edit.pack(side="right", expand=True, fill="both") # 按钮 self.btn_new = tk.Button(self.root, text="新建", command=self.new_note) self.btn_new.pack() ``` **2. 功能实现(增删改查)** ```python def new_note(self): title = "未命名笔记" timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") self.note_list.insert("", "end", values=(title, timestamp)) def save_note(self): content = self.text_edit.get("1.0", "end-1c") # 保存到SQLite数据库 import sqlite3 conn = sqlite3.connect('notes.db') cursor = conn.cursor() cursor.execute("INSERT INTO notes (title, content) VALUES (?, ?)", (title, content)) conn.commit() ``` **3. 数据存储(SQLite示例)** ```python # 初始化数据库 conn = sqlite3.connect('notes.db') cursor = conn.cursor() cursor.execute('''CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, title TEXT, content TEXT, timestamp TEXT)''') conn.close() ``` --- #### 三、工具与资源 1. **开发环境**: - 推荐使用**VS Code**或**PyCharm**(引用[4]提到的配置) - 调试工具:Jupyter Notebook可辅助代码测试[^2] 2. **学习资源**: - Tkinter官方文档:[https://docs.python.org/3/library/tkinter.html](https://docs.python.org/3/library/tkinter.html) - PyQt教程:[Real Python教程](https://realpython.com/python-pyqt-gui-calculator/) --- #### 四、扩展功能建议 - 添加**Markdown渲染**(使用`markdown2`库) - 实现**云同步**(集成Dropbox API) - **搜索功能**:通过SQL查询或全文检索 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值