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): ...
随机推荐
- swift语言点评十-Value and Reference Types
结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...
- 在vue组件中style scoped中遇到的坑
在uve组件中我们我们经常需要给style添加scoped来使得当前样式只作用于当前组件的节点.添加scoped之后,实际上vue在背后做的工作是将当前组件的节点添加一个像data-v-1233这样唯 ...
- Node_进阶_8
Node进阶第八天 一.复习 Node.js特点:单线程.异步I/O(非阻塞I/O).事件驱动(事件环). 适合的程序:就是没有太多的计算,I/O比较多的业务. 举例:留言本.考试系统.说说.图片裁切 ...
- Linux下重启mysql数据库的方法
原文地址:Linux下重启mysql数据库的方法作者:于士博的视频教程 方法一: 命令: [root@localhost /]# /etc/init.d/mysql start|stop|rest ...
- [HEOI2012]采花(树状数组+离线)
听说这题的所发和HH的项链很像. 然而那道题我使用莫队写的... 这是一个套路,pre数组加升维(在线). 记录一个\(pre\)数组,\(pre[i]\)代表上一个和i颜色相同的下标. 我们把询问离 ...
- [SHOI2009]Booking 会场预约
题目:洛谷P2161. 题目大意:有一些操作,分为两种: A.增加一个从第l天到第r天的预约,并删除与这个预约冲突的其他预约,输出删除了多少个预约. B.输出当前有效预约个数. 两个预约冲突定义为两个 ...
- caioj 1155 同余方程组(模版)
第一步,和同余方程一样,转化一下 两式相减得 这就转化为了求不定方程,用exgcd 求出x,要化成最小正整数解,避免溢出 然后可以求出P出来. 这个时候要把前两个式子转化成一个式子 设求出来的是P' ...
- 紫书 习题 8-2 UVa 1610 (暴力出奇迹)
这道题我真的想的非常的复杂, 拿草稿纸一直在找规律,推公式, 然后总有一些特殊的情况. 然后就WA了N次.无奈之下看了别人的博客, 然后就惊了.直接暴力枚举两个相邻字符串 里面的所有可能就可以了--真 ...
- docker安装MySQL8,目录挂载、配置用户名密码、忽略表名大小写、连接数、特殊字符、时区
原文:docker安装MySQL8,目录挂载.配置用户名密码.忽略表名大小写.连接数.特殊字符.时区 一.环境配置 1.系统:centos7.3 2.docker版本:Docker version 1 ...
- COGS——T 803. [USACO Hol10] 政党 || 1776: [Usaco2010 Hol]cowpol 奶牛政坛
http://www.lydsy.com/JudgeOnline/problem.php?id=1776||http://cogs.pro/cogs/problem/problem.php?pid=8 ...