python note #1
To record my process of studying python and to practice my English meanwhile, I'd like to start write my blog about python with English. = ^ =
Part 1_Hello World!
print (' Hello World! ')
This code can show the best reason why I'd like to study python. Because it's so simple, clean and elegant. With python, setting language environment is not needed anymore. Just use 'print', everything is done!
Part 2_History & Development of Character Encoding
- ASCII: best for English, which only takes up 1 bytes of your storage.
- Chinese: take up 3 bytes

- Unicode: ISO released unicode to unite diffrent standards of character encoding between countries. But it took up 2 bytes to store English. To improve it, utf-8 was released. With utf-8, only 1 bytes was needed while storing English.
Part 3_Variety
Rules
- Combination of character, number and underscores.
- Don't use key words as the name of the variety.
- Name the variety with its meaning.
- With CAPITAL LETTERS naming a variety, it means that the variety is constant.
How to use?
name = 'It's a good day!'
# name a variety
name2 = name
# give a value to a new variety
print (' What' the weather like today?', name, name2)
# use varieties
variety
'''
function1:多行注释
function2:多行打印
'''
message='''
Do you like this blog?
If yes, that's great!
If no, leave you suggestions, and I'll improve it ASAP!
'''
print(message)
usage of '''
Part 4_Interaction
'Input' is used to get information from users. And 'print' is used to output the information.
name = input (' Please input your name:')
age = input("Please input your age:")
#加入int,代表integer,整型,字符串的格式化
job = input("Please input your job:")
salary = input("Please input your salary:")
info = '''
-------------------info of {NAME} --------------------------
NAME: {NAME}
AGE: {AGE}
JOB: {JOB}
SALARY: {SALARY}
----------------------------------------------------------------
''' .format(NAME=name, AGE=age, JOB=job, SALARY=salary)
print (info)
interaction
Part 5_Loop ( if, elif, for, while )
Combination of If, While and Elif
Qiao is one of my roomates. To show my respect for her, I took advantage of her birth year information to write a code for you to guess. Ofcourse, please do not read the code directly. Cuz in this way, you'll get the answer directly...
birthyear_of_qiao = 1997
count = 0
while count<3:
guess = int(input("猜猜乔的出生年份:"))
if guess == birthyear_of_qiao:
print("干的漂亮,你猜对了!")
break
elif guess > birthyear_of_qiao:
print("她哪有那么年轻?!!!")
else:
print("她还没那么老,好嘛。。。")
count +=1
if count == 3:
if_continue = input('是否要继续呢?继续的话请输入Y,退出的话请输入N:')
if if_continue == 'Y':
count = 0
else:
print ('猜不中还早早退出,太塑料兄弟情了!')
break
else:
print('游戏失败。。。')
loop_if_while_elif
For
# continue是跳出本次循环,进入到下一次循环
# break是结束全部循环
for i in range(0,10,2):
if i <5:
print("loop",i)
else:
continue
print('嘻嘻') # 循环套循环,执行一次大循环,下面执行六次小循环
for i in range(10):
print ('-------------------',i)
for j in range(10):
print(j)
if j>5:
break
python note #1的更多相关文章
- python note
=和C一样,为赋值.==为判断,等于.但是,在python中是不支持行内赋值的,所以,这样避免了在判断的时候少写一个出错. dictionary 的key唯一,值可以为很多类型. list的exten ...
- python note 4
1.使用命令行打开文件 t=open('D:\py\123.txt','r') t.read() 在python和很多程序语言中""转义符号,要想输出\要么多加一个\写成\ 要么在 ...
- python note 17 random、time、sys、os模块
1.random模块(取随机数模块) # 取随机小数 : 数学计算 import random print(random.random())# 取0-1之间的小数 print(random.unifo ...
- python note 16 re模块的使用
1.re模块(#regex) # 查找 # findall : 匹配所有 每一项都是列表中的一个元素 import re ret = re.findall('\d+','dawdawd154wadwa ...
- python note 15 正则表达式
# 正则表达式 只和字符串打交道 # 正则表达式的规则# 规则 字符串 从字符串中找到符合规则的内容 # 字符组 : [] 写在中括号中的内容,都出现在下面的某一个字符的位置上都是符合规则的 # [0 ...
- python note 12 生成器、推导式
1.生成器函数 # 函数中如果有yield 这个函数就是生成器函数. 生成器函数() 获取的是生成器. 这个时候不执行函数# yield: 相当于return 可以返回数据. 但是yield不会彻底中 ...
- python note 10 函数变量
1.命名空间 #内置命名空间 —— python解释器 # 就是python解释器一启动就可以使用的名字存储在内置命名空间中 # 内置的名字在启动解释器的时候被加载进内存里#全局命名空间 —— 我们写 ...
- python note 01 计算机基础与变量
1.计算机基础. 2.python历史. 宏观上:python2 与 python3 区别: python2 源码不标准,混乱,重复代码太多, python3 统一 标准,去除重复代码. 3.pyth ...
- python note of decorator
def decorate_log(decorate_arg,*args,**kwargs): # 存放装饰器参数 def decorate_wrapper(func,*args,**kwargs): ...
随机推荐
- 你不知道的JavaScript博文参考书籍
you don't know js系列书籍是谷歌地图开发人员编写,内容非常好,四卷已收集齐全. 笔者打包上传到了CSDN,下载地址: http://download.csdn.net/detail/r ...
- PC比价软件
方法:从百度中搜索比较软件排行,并且根据将搜索时间缩小在一年内.统计前面一页结果网站中的比价软件. 名称 备注 统计 淘淘搜购物助手 淘宝购物比价神器 1 省省比价软件 主流网购商城进行横向比较的智能 ...
- layui计算剩余时间
<div id="test"></div> <script> layui.use('util', function(){ var util = ...
- [agc004d]salvage robot
题意: 别问我谁翻译的 虫合虫莫国的领土我们可以抽象为H*W的笼子,在这虫合土上,有若干个机器人和一个出口,其余都是空地,每次虫合虫莫会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被虫 ...
- 利用MFC创建窗口、消息映射、window中的字节
利用MFC创建窗口: 1.mfc的头文件:afxwin.h 2.自定义类,继承于CWinApp,应用程序类(app应用程序对象,有且仅有一个) 3.程序入口:Initinstance 4.在程序入口中 ...
- dropload上拉加载 下拉刷新
1.引入css.js <link rel="stylesheet" href=" ${pageContext.request.contextPath}/dist/d ...
- FastDFS图片服务器搭建
*FastDFS图片服务器搭建准备:1.需要libfastcommon安装包 选择最新稳定版(libfastcommon-1.0.36.tar.gz)2.需要FastDFS安装包 选择最新稳定版(fa ...
- 【转】Geometry cannot have Z values
http://blog.csdn.net/tweeenty/article/details/44246407 在对矢量要素类添加要素,进行赋几何信息时(FeatureBuffer.Shape = IG ...
- HDU--4891--The Great Pan--暴力搜索
The Great Pan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...