python个人总结_初识Python
Program01 基本的输出
作为一种语言的学习,他的仪式感很重要
print("Hello World!")
这就是python3里面的 Hello World! 打印输出
Program02 注释符号的使用
name = "你好,世界"msg= """print(name)
666
777
888"""name2= name+"111"
print(name)print(name2)print("My name is",name,"Hello world")print(msg)
输出结果:
你好,世界
你好,世界111
My nameis你好,世界 Hello worldprint(name)666
777
888
'''在python3中 三个连续的引号是多行注释'''
此程序中可以学到:python3中 ''' 表示多行注释,如果将注释掉的内容赋值给一个变量,
print一下是可以打印输出的,单行注释使用的是 #
Program03 多种方式打印个人信息
name = input("name:")
age= int(input("age:")) #integer 将字符串转化为整数型
print( type(age), type( str(age)))
job= input("job:")
salary= input("salary:")
info= '''-------- info of %s--------
Name: %s
age: %d
job: %s
salary: %s'''%(name,name,age,job,salary)print(info)
输出结果:
name:XiaoBai
age:11
job:Student
salary:1000
-------- info of XiaoBai--------Name: XiaoBai
age:11job: Student
salary:1000
name = input("name:")
age= int(input("age:")) #integer 将字符串转化为整数型
print( type(age), type( str(age)))
job= input("job:")
salary= input("salary:")
info= '''-------- info of %s--------
Name: %s
age: %d
job: %s
salary: %s'''%(name,name,age,job,salary)
info2= '''-------- info of {_name} --------
# 此处下划线仅仅是为了区别name 这一个变量
Name: {_name}
age: {_age}
job: {_job}
salary: {_salary}'''.format(_name =name,
_age=age,
_job=job,
_salary=salary)print(info2)
输出结果:
name:xiaobai
age:11
job:Student
salary:1000
-------- info2 of xiaobai --------
# 此处下划线仅仅是为了区别name 这一个变量
Name: xiaobai
age: 11
job: Student
salary: 1000
name = input("name:")
age= int(input("age:")) #integer 将字符串转化为整数型
job = input("job:")
salary= input("salary:")
info= '''-------- info of %s--------
Name: %s
age: %d
job: %s
salary: %s'''%(name,name,age,job,salary)
info3= '''-------- info3 of {0} --------
Name: {0}
age: {1}
job: {2}
salary: {3}'''.format(name,age,job,salary)print(info3)#打印整段,%s 是段内调用段外的字符串
# 在此方法中输入时,format()中的name只写了一次!
输出结果:
name:xiaobai
age:11job:Stu
salary:1000
-------- info3 of xiaobai --------Name: xiaobai
age:11job: Stu
salary:1000
总结:
'''时间 2018年2月6日21:08:12
目的 学习python输入、输出
记录 通过input输入的默认格式是str,可以通过int()强制类型转化为int类型
通过type 可以查询目标元素的格式和类型
三个引号(不区分单双)可以注释一整段,如果将注释掉的内容赋值
给一个变量那么可以打印输出该段内容
使用format的时候不要忘记加 .
灵活运用三种打印输出段落,并对外部内容引用的方式。其中第二种最为常见
而且一个{} 中只写一个变量名称
input("登录用户{m},{n}?".format(m = user_name01,n = user_name02)) correct
input("登录用户{m,n}?".format(m = user_name01,n = user_name02)) error'''
Program04 判断语句
'''时间 2018年2月6日21:14:05
目的 if else 流程判断
记录 隐藏密文
而且python是强制缩进,同级会同时输出'''
importgetpass
_username= 'abc'_password= 'abc123'username= input("username:")#password = getpass.getpass("password:") 此时是密文,隐藏密码
password = input("password:")print(username,password)if _username == username and _password ==password:print("Worlcome user {name} login...".format(name =username))else:print("Invalid username or password!")
输出结果:
username:abc
password:abc123
abc abc123
Worlcome user abc login...
总结:
#if执行语句必须含有缩进,否则会报错!
Program05 while循环语句
'''时间 2018年2月6日22:03:14
目的 继续测试while 循环
记录 while 循环需要加冒号'''age_of_boy= 56count=0while count < 3:
guess_age= int(input("guess age:"))if guess_age ==age_of_boy:print("yes,you got it.")break
elif guess_age >age_of_boy:print("think smaller...")else:print("think bigger...")
count+= 1
if count == 3:
continue_confirm= input("do you want to keep gussing?")if continue_confirm != 'n':
count= 0
输出结果:
guess age:10think bigger...
guess age:100think smaller...
guess age:50think bigger...
do you want to keep gussing?n
Program06 for循环语句
'''目的 测试for 循环
记录 从此可以看出,python中的循环和MATLAB中的循环与构建向量有相似之处'''age_of_boy= 56
for i in range(3):
guess_age= int(input("guess age:"))if guess_age ==age_of_boy:print("yes,you got it.")break
elif guess_age >age_of_boy:print("think smaller...")else:print("think bigger...")else:print("you have tried too many times...have a rest")#特别值得注意的一点是 在python中if-elif-else语句的写法#break 和 continue的区别是 前者终止当前循环,后者是跳出本次循环,进入下一次循环
输出结果:
think bigger...
guess age:70think smaller...
guess age:60think smaller...
you have tried too many times...have a rest
Program07 简易用户登录界面
'''时间 2018年2月10日19:51:29
目的 制作一个用户登录界面,能够提示用户输入密码,三次出错锁定
# 还有小问题是不会使用python对文件进行增删改查的操作,此次操作的用户名和用户密码最好是在文件中'''user_name01= 'abc'user_name02= 'bcd'user_pass01= 'abc123'user_pass02= 'bcd123'
#用于提示用户被锁住,无法登录
user_flag01 =True
user_flag02=True
count=0
choice= input("登录用户{m},{n}?".format(m = user_name01,n =user_name02))if choice == user_name01 and user_flag01 isTrue:while count < 3:
pass_01= input("please input the pass word of {na}:".format(na =user_name01))if pass_01 ==user_pass01:print("congratulations!you passed \t")break
else:print("try again:")
count+= 1
else:
userflag01=Falseprint("you hava tried so many times,the id is locked")elif choice == user_name02 and user_flag02 isTrue:while count < 3:
pass_02= input("please input the pass word of {nb}:".format(nb =user_name02))if pass_02 ==user_pass02:print("congratulations!you passed \t")break
else:print("try again:")
count+= 1
else:
userflag02=Falseprint("you hava tried so many times,the id is locked")
输出结果:
登录用户abc,bcd?abc
please input thepassword of abc:abcabctryagain:
please input thepassword of abc:acb123tryagain:
please input thepassword of abc:abc123
congratulations!you passed
Program08 字典的使用
#三级菜单的创建#思路 通过字典存储
'''时间 2018年2月10日20:34:03
目的 创建一个三级菜单
记录 利用函数简化此代码,pass不进行任何操作
总结 2018年2月11日重新编写并运行此代码,发现一些错误
在重新编写之后,发现python是严格的格式对齐语言,如果同时存在while 和 for 的时候,
二者没有区分循环层次,误将二者对齐,则会报错。在之后的一系列测试中发现,循环体的
书写位置也会影响代码的运行结果!'''data={'北京':{"昌平":{"沙河":["oldboy","test"],"天通苑":["链家地产","我爱我家"]
},"朝阳":{"望京":["奔驰","陌陌"],"国贸":{"CICC","HP"},"东直门":{"Advent","飞信"},
},"海淀":{},
},'山东':{"德州":{},"青岛":{},'济宁':{'兖州':["BBQ","TYZY"],'太白':["JNYX","FSYY"]
},'济南':{'历下':["山大","山交通"],'长清':["山师","山工艺"]
}
},
}
exit_flag=Falsewhile notexit_flag:for i indata:print(i)
choice= input("选择进入1>>:")if choice indata:while notexit_flag:for i2 indata[choice]:print("\t",i2)
choice2= input("选择进入2>>:")if choice2 indata[choice]:while notexit_flag:for i3 indata[choice][choice2]:print("\t\t", i3)
choice3= input("选择进入3>>:")if choice3 indata[choice][choice2]:for i4 indata[choice][choice2][choice3]:print("\t\t",i4)
choice4= input("最后一层,按b返回>>:")if choice4 == "b":pass
elif choice4 == "q":
exit_flag=Trueif choice3 == "b":break
elif choice3 == "q":
exit_flag=Trueif choice2 == "b":break
elif choice2 == "q":
exit_flag=True
MYK
2018年2月11日
python个人总结_初识Python相关推荐
- 用python画竹子_初识Python
一:编程语言的分类 (1)机器语言 机器语言是用二进制代码表示的计算机能直接识别和执行的一种机器指令的集合. (2)汇编语言 汇编语言采用的是英文缩写,标识符更容易识别和记忆,它同样需要编程者将每一步 ...
- python程序保存_初识python 文件读取 保存
上一章最后一题的答案: infors.sort(key=lambda x:x['age']) print(infors) --->[{'name': 'laowang', 'age': 23}, ...
- python序列符号_初识Python(4)__Python序列
序列 序列包含:字符串,列表和元组 序列基本操作符 索引:seq[ind] 获得下标为ind 的元素 分片( [], [:], [::] ):seq[ind1:ind2] 获得下标从ind1 到ind ...
- 初识python教学反思_初识Python
引子 计算机编程语言如同我们的自然语言一样,有其一套规范的语法,我们学习编程语言不过是学习它的那一套规则罢了. 语言的发展史 机器语言 --> 汇编语言 --> C语言(写程序时需要操作内 ...
- python输入姓名 性别身高_孤荷凌寒自学python第十一天初识Python的字典类
孤荷凌寒自学python第十一天初识Python的字典类 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python的字典其实是一张二维对照表 下面举例说明: 键名Key 姓名 性别 身高 ...
- python自学第8天字典_孤荷凌寒自学python第十一天初识Python的字典类
孤荷凌寒自学python第十一天初识Python的字典类 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python的字典其实是一张二维对照表 下面举例说明: 键名Key 姓名 性别 身高 ...
- 孤荷凌寒自学python第三十八天初识python的线程控制
孤荷凌寒自学python第三十八天初识python的线程控制 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.线程 在操作系统中存在着很多的可执行的应用程序,每个应用程序启动后,就可以看着 ...
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
最新文章
- 【Spring学习笔记】之【3.3 DI的深入 二】
- REST、SOAP、protocolbuf、thrift、avro
- [导入]体验Asp.Net Mvc Preview5(3)-探索ModelBinder的工作原理
- 【HDU - 1247】Hat’s Words(字典树,预处理,tricks)
- screnc加密后文件不能执行_芯片加密后还能不能再次使用【详细介绍】
- oracle缓存怎么看,Oracle从缓存里面查找真实的执行计划
- 【leetcode❤python】Intersection of Two Arrays
- VUE配置本地代理服务器
- MWL/Modality Worklist SCP、Wordlist成像设备工作列表
- Google浏览器安装插件
- abaqus·复合材料建模技术与应用
- 2022软件项目管理案例教程期末考知识点汇总(期末复习用)
- 国家开放大学2021春1315社会调查方法题目
- 自学Python第二十六天- Tornado 框架
- 1.CSS3 教程-> 多列布局 > image模块 > cssTransition 过渡 > CSS Animations 动画 > Transform二维
- 编程语言学习——0基础C语言入门
- 计算机科学着重于理论和算法,大学计算机-中国大学mooc-题库零氪
- VS Code 网易云音乐插件 没有声音 无法播放的解决办法
- spoolsv病毒的清除
- ewebeditor漏洞之目录遍历漏洞
热门文章
- 小白日记18:kali渗透测试之缓冲区溢出实例(二)--Linux,穿越火线1.9.0
- 虚拟主机或者网站服务器,网站服务器空间(也称:虚拟主机,或者云主机)
- GoLand实用技巧
- 揭秘MOS管在音响功放中的详细应用
- 防弹眼镜解决安全问题
- 程序员要注意身体健康
- 苹果nfc功能怎么开启_【每日一技】苹果iPhone如何开启NFC功能?
- 【附源码】Python计算机毕业设计企业人事管理系统
- uniapp 上传附件
- t40服务器连接显示器的接口,如何选择显示器连接线?VGA、DVI、HDMI、DP四种主流接口知识...