差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
| public:it:python [2014/12/03 16:54] – oakfire | public:it:python [2024/01/15 15:33] (当前版本) – [Tips] oakfire | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== Python ====== | ====== Python ====== | ||
| * [[https:// | * [[https:// | ||
| + | * [[http:// | ||
| ===== Tips ===== | ===== Tips ===== | ||
| * 快速开一个静态http服务: | * 快速开一个静态http服务: | ||
| * In Terminal, type '' | * In Terminal, type '' | ||
| - | * python为动态语言, | + | * python为动态语言, |
| + | * python 变快的 9 个技巧:[[https:// | ||
| + | * 拼接字符串的速度, | ||
| + | * Faster List Creation: Use “[]” Over “list()” 用 '' | ||
| + | * Faster Membership Testing: Use a Set Over a List | ||
| + | * Faster Data Generation: Use Comprehensions Over For Loops 用内包代替循环 | ||
| + | * Faster Loops: Prioritize Local Variables 优先使用局部变量 | ||
| + | * Faster Execution: Prioritize Built-In Modules and Libraries 优先用内置模块和库 | ||
| + | * Faster Function Calls: Leverage Cache Decorator for Easy Memoization | ||
| + | * Faster Infinite Loop: Prefer “while 1” Over “while True” 但是现代解释器基本都优化过, '' | ||
| + | * Faster Start-Up: Import Python Modules Smartly | ||
| ===== 从零开始 ===== | ===== 从零开始 ===== | ||
| - | * [[http:// | + | * [[http:// |
| - | * <code python> | + | * Learning more: |
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * Notes:<code python> | ||
| # ------------------------------------------------------------------------- | # ------------------------------------------------------------------------- | ||
| # ex1: Print | # ex1: Print | ||
| 行 348: | 行 373: | ||
| super(Child, | super(Child, | ||
| | | ||
| - | # ex45: You Make a Game | + | # ex45: You Make a Game |
| - | | + | # Nothing impresses me. |
| + | |||
| + | # ------------------------------------------------------------------------- | ||
| + | # ex46: A Project Skeleton | ||
| + | try: | ||
| + | from setuptools import setup | ||
| + | except ImportError: | ||
| + | from distutils.core import setup | ||
| + | |||
| + | # ------------------------------------------------------------------------- | ||
| + | # ex47: Automated Testing | ||
| + | nosetests | ||
| + | from nose.tools import * | ||
| + | assert_equal | ||
| + | # Test files go in " | ||
| + | |||
| + | |||
| + | # ------------------------------------------------------------------------- | ||
| + | # ex48: Advanced User Input | ||
| + | # A tuple is nothing more than a list that you can't modify. | ||
| + | # It's created by putting data inside two " | ||
| + | first_word = (' | ||
| + | # Exceptions and Numbers | ||
| + | def convert_number(s): | ||
| + | try: | ||
| + | return int(s) | ||
| + | except ValueError: | ||
| + | | ||
| + | |||
| + | # ------------------------------------------------------------------------- | ||
| + | # ex49: Making Sentences | ||
| + | # ex50: Your First Website | ||
| + | # ex51: Getting Input from a Browser | ||
| + | # ex52: The Start Of Your Web Game | ||
| + | # Nothing impresses me. | ||
| + | |||
| </ | </ | ||