Python基础-_main_ 写在前面 如非特别说明,下文均基于Python3 一.__main__的官方解释 参考 _main_ -- Top-level script environment '_main_' is the name of the scope in which top-level code executes. A module’s _name_ is set equal to '_main_' when read from standard input, a script,…
一.前言 初学python,看<python基础教程>,第20章实现了将文本转化成html的功能.由于本人之前有DIY一个markdown转html的算法,所以对这个例子有兴趣.可仔细一看,发现很难看懂,一个功能分散在几个文件中,各个类的耦合非常紧.虽然自己有几年的c++开发经验,但初看这个python代码也觉得头晕. 二.原版 以下是其源码 from __future__ import generators def lines(file): for line in file: yield l…
四. Python基础(4)--语法 1 ● 比较几种实现循环的代码 i = 1 sum = 0 while i <= 10: # 循环10-1+1=10次 sum += i i += 1 print(sum) sum = 0 for i in range(1, 11): # 循环11-1=10次 sum += i print(sum) i = 0 sum = 0 while True: i += 1 if i <=10: sum…
一. Python基础(1)--语法 1. 应用程序 1.1 什么是计算机(Computer)? 组成 ①运算器 arithmetic unit; ※ Arithmetic unit and control unit are collectively called as CPU. ②控制器 control unit; ③存储器 memory unit; ·内部存储器 (内存) internal memory/internal storage; also called: main memory (…
pythonic 风格编码 入门python好博客 进阶大纲 有趣的灵魂 老齐的教程 老齐还整理了很多精华 听说 fluent python + pro python 这两本书还不错! 元组三种遍历,有点像回字有四种写法一样...苦笑 for index in range(0,len(tuple_1)): ... print(tuple_1[index]) >>> for index in range(0,len(tuple_1)): ... print('{}--{}'.format(…
Python基础-_main_ 写在前面 如非特别说明,下文均基于Python3 一.__main__的官方解释 参考 _main_ -- Top-level script environment '_main_' is the name of the scope in which top-level code executes. A module's _name_ is set equal to '_main_' when read from standard input, a script,…