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): ...
随机推荐
- 利用canvas做一个简单个gif停止和播放
var ImagePlayer = function(options) { this.control = options.control; this.image = options.image; th ...
- sqluldr2linux64.bin的使用
使用sqluldr2linux64.bin的前提是已经安装了Oracle数据库,sqluldr2linux64.bin和Oracle在同一台主机上使用,使用之前需要赋予可执行权限: [root@nod ...
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...
- VB学习笔记(一)VB操作字符串
在vb中 dim a# 定义a变量为双精度型变量~ #是类型符 % 整型 & 长整型 !单精度 $ 字符型 VB中strconv 的作用 StrConv("要转换的字符串" ...
- How Javascript works (Javascript工作原理) (二) 引擎,运行时,如何在 V8 引擎中书写最优代码的 5 条小技巧
个人总结: 一个Javascript引擎由一个标准解释程序,或者即时编译器来实现. 解释器(Interpreter): 解释一行,执行一行. 编译器(Compiler): 全部编译成机器码,统一执行. ...
- mysql 临时表和内存表
查看内存表的最大值: show variables like '%heap%'; mysql> show variables like '%heap%'; +------------------ ...
- webpack 操作
依赖安装 : 全局安装webpack : sudo npm install webpack -g 本地安装webpack : npm install webpack —save-dev 需要注意的 ...
- redis做成windows服务
打开cmd切换到redis根目录 执行安装命令 redis-server.exe --service-install redis.windows.conf --loglevel verbose 卸载 ...
- Innodb中的事务隔离级别和锁的关系(转载)
nodb中的事务隔离级别和锁的关系 原文:https://tech.meituan.com/innodb-lock.html ameng ·2014-08-20 15:50 前言: 我们都知道事务的几 ...
- java读取excel文件内容
1.导入依赖JAR包 <!-- jxl 操作excel --> <dependency> <groupId>org.jxls</groupId> < ...