• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
pangzipangpang走过的路
博客园    首页    新随笔    联系   管理    订阅  订阅

【Python开发web】(3) -- Python基础之一

开始静下心来认真学习Python的基础:The Python Tutorial

今天看了前面的一些章节,见下图:

章节

 

---------------------我是pangpang分隔线---------------------

 

值得关注的要点有:

1) 中文字符的长度

经测试,一个中文字符占3个,见下图

中文长度

 

---------------------我是pangpang分隔线---------------------

 

2) 在一些语言中,“=”代表引用,在Python中是复制而非引用,见下图:

function

 

---------------------我是pangpang分隔线---------------------

 

3) 在调用函数时,不按参数的顺序,直接指定参数名和值也可以传递,见下图:

参数

 

----------------------我是pangpang分隔线---------------------

 

4) Python的代码规范,直到看到这段文字后,我才将Tab改为了4-space,受教了。 

 

Now that you are about to write longer, more complex pieces of Python, it is a good time to talk about coding style. Most languages can be written (or more concise, formatted) in different styles; some are more readable than others. Making it easy for others to read your code is always a good idea, and adopting a nice coding style helps tremendously for that.

For Python, PEP 8 has emerged as the style guide that most projects adhere to; it promotes a very readable and eye-pleasing coding style. Every Python developer should read it at some point; here are the most important points extracted for you:

  • Use 4-space indentation, and no tabs.

    4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.

  • Wrap lines so that they don’t exceed 79 characters.

    This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.

  • Use blank lines to separate functions and classes, and larger blocks of code inside functions.

  • When possible, put comments on a line of their own.

  • Use docstrings.

  • Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).

  • Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument (see A First Look at Classes for more on classes and methods).

  • Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.

posted @ 2009-03-13 16:39  pangzi  阅读(1676)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3