python - one day
1. python历史。
2008 年出现 python 2.7 与 python 3.0 两个版本,后来 吉多·范罗苏姆 大叔决定停用 python 2.7,但因用户反对,于是决定于 2020 年停止 python 2.7 的更新
宏观上:
python2 与 python3 区别:python2 源码不标准,混乱,重复代码太多,python3 统一 标准,去除重复代码
2. python的环境
编译型:一次性将所有程序编译成二进制文件
缺点:开发效率低,不能跨平台
优点:运行速度快
比如:C,C++等等
解释型:当程序执行时,一行一行的解释
缺点:运行速度慢
优点:开发效率高,可以跨平台
比如:python ,php,等等
3. python种类
运行第一个py文件:
python3x :python 文件路径 回车
python2x :python2 文件路径 回车
python2 python3 区别:python2默认编码方式是ascii码
解决方式:在文件的首行:#-*- encoding:utf-8 -*-
python3 默认编码方式utf-8
4. 变量
变量:就是将一些运算的中间结果暂存到内存中,以便后续代码调用
1. 必须由数字,字母,下划线任意组合,且不能数字开头
2. 不能是python中的关键字,如:['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
3. 变量具有可描述性
4. 不能是中文
x=1+2+3+4+5 print(x) print(1+2+3+4+5) print(x*5) print(x*5-234+2)x='sjd' print(x) 名字='亦双弓' print(名字)age1 = 12 age2 = 100 age2 = age1 age3 = age2 #age2 = 100 print(age1,age2,age3)
5. 常量
常量:一直不变的量 ,如:圆周率 π
BIR_OF_CHINA = 1949 ,python中没有常量,约定俗成的大写为常量
6. 注释
注释: 方便自己方便他人理解代码
单行注释:#
多行注释:'''被注释内容''' """被注释内容"""
当引用换行的语句时应该用 3 个单引号或双引号进行引用 """ 我今天写了一首小诗 歌颂我爱人 你看她那乌黑亮丽的头发 啊!好像一只炸毛鸡 ''' mg='''我今天写了一首小诗 歌颂我爱人 你看她那乌黑亮丽的头发 啊!好像一只炸毛鸡 ''' print (mgr,mg)
7. 用户交互:input
1.待输入
2.你输入的内容赋值给了前面变量
3. input 出来的数据类型全部是 str
print (True,type(True)) print ('True',type('True'))name = input('you name:') age = input("you age:") print ("my name is "+name,",age is "+age) print (name,age,type('age'))
8. 基础数据类型初始
数字:int 12,3,45 + - * / ** % 取余数
ps:type()
字符串转化成数字:int(str) 条件:str必须是数字组成的
数字转化成字符串:str(int)
字符串:str,python当中凡是用引号引起来的都是字符串
可相加:字符串的拼接
可相乘:str * int
bool:布尔值, True False
int = 100 print(100,type(100)) print(100.3,type(100.3)) print('100', type('100')) print("100", type("100"))print("I am ysg") #print('i'm ysg') print("I'm ysg,i'm ysg")a="ysg" b="peipei" c=a+b e=100 f=100 print(c) print(a+b) #print(a+b) print("坚强"*4) #print("坚强坚强坚强坚强"/2) #print(e=f)
9. if 判断语句
if 条件: 结果
#语法结构 # if if True :print(666) if 4<5 :print(777) if 5<3 :print(555) if False :print(222)if 9<7 :print("你请我喝酒") else:print('喝什么酒')num=input("请输入你选择的数字:") if int(num)<5 :print ("小") elif 5<int(num)<10 :print("大") elif int(num) == 5:print("中") else :print("输错了")num=int(input("请输入你选择的数字:")) if num<5 :print ("小") elif 5<num<10 :print("大") elif num == 5:print("中") else :print("输错了")print("111") while True:print('我们不一样')print('丑八怪') print('222')
10. while 循环语句
while 条件:
循环体:无限循环
终止循环:
1. 改变条件,使其不成立
2. continue 结束本次循环
3. break 跳出循环结构
#while 循环 count = 1 flag=True while flag:print(count)count=count+1if count > 10:flag=Falsecount =1 while count<10:print(count)count=count+1count = 1 sun=0 while count <=100:sun=sun+countcount=count+1print(sun)#break print("111") while :print("222")#breakprint("333")count=0 while True:count = count+1if count==5:continueprint(count)if count >10:break count = 0while count <100: count += 1 if count > 5 and count < 95: continue print("loops:",count)print ("loop---------loop")
相关练习
1. 使用 while 循环输出 1 2 3 4 5 6 8 9 10
count = 0 while count<10:count +=1if count==7:continueprint(count)
2. 求 1-100 的数之和
count=1 sun=0 while count<=100:sun +=countcount +=1print(sun)
3. 输出 1-100 的所有奇数
count=0 while count<100:count+=1if count%2==1:print(count)
4. 输出 1-100 的所有偶数
count = 0 while count<100:count+=1if count%2==0:print(count)
5. 求 1-2+3-4+5...99 的所有数的和
count=1 sum=0 while count<=99:if count%2==1:sum+=countelse:sum-=countcount+=1 print(sum)
6.用户登录(三次机会重试)
i=0 while i<3:username=input('请输入用户名:')userpw=input('请输入密码:')if username=="亦双弓" and userpw=='123123':print('欢迎'+username+'回来')breakelif i==2:print('密码输入次数超限,已被冻结')else:print('---密码输入错误,请重新输入---')i+=1
转载于:https://www.cnblogs.com/ysging/p/9610298.html
python - one day相关推荐
- Github配置(git+vscode+python+jupyter)
①下载git 打开 git bash 工具的用户名和密码存储 $ git config --global user.name "Your Name" $ git config -- ...
- 【实验楼】python简明教程
①终端输入python进入 欣赏完自己的杰作后,按 Ctrl + D 输入一个 EOF 字符来退出解释器,你也可以键入 exit() 来退出解释器. ②vim键盘快捷功能分布 ③这里需要注意如果程序中 ...
- 【Kaggle Learn】Python 5-8
五. Booleans and Conditionals Using booleans for branching logic x = True print(x) print(type(x))''' ...
- 【Kaggle Learn】Python 1-4
[Kaggle Learn]Python https://www.kaggle.com/learn/python 一. Hello, Python A quick introduction to Py ...
- 使用python愉快地做高数线代题目~
今天接触到了python,发现真是极易上手啊!对比c语言是什么鬼东西= = 诶,等下,看完教学文章发现TA在下面写了这句话 如果做了前面的内容你可能已被吸引了,觉得c语言真的是废材! 不...不是的. ...
- python 位运算与等号_Python 运算符
和大多数语言一样,Python也有很多运算符,并且运算符跟其他语言的运算符大同小异接下来一一介绍: 算术运算符: 运算符描述实例 +加 - 两个对象相加a+b的输出结果是30 -减 - 得到复数或者一 ...
- python减小内存占用_如何将Python内存占用缩小20倍?
当程序执行过程中RAM中有大量对象处于活动状态时,可能会出现内存问题,特别是在对可用内存总量有限制的情况下. 下面概述了一些减小对象大小的方法,这些方法可以显著减少纯Python程序所需的RAM数量. ...
- python中排序英文单词怎么写_Python实现对文件进行单词划分并去重排序操作示例...
本文实例讲述了Python实现对文件进行单词划分并去重排序操作.,具体如下: 文件名:test1.txt 文件内容: But soft what light through yonder window ...
- python程序如何执行死刑图片_如何判断对象已死
已死的对象就是不可能被任何途径使用的对象,有以下几种方法判断一个对象是否已经死了: 引用计数 给对象添加一个引用计数器,每当有一个地方引用他,计算器就加 1:当引用失效时,计数器减 1:任何时刻计数器 ...
- Python gRPC 安装
1. 安装依赖库 sudo pip3 install grpcio sudo pip3 install protobuf sudo pip3 install grpcio_tools 2. 生成对应文 ...
最新文章
- Delphi 调用C#编写的WebService
- fork() || fork()和fork() fork()笔试题
- c/c++的全局变量
- Spring之WebSocket网页聊天以及服务器推送
- Win10应用商店无法连接解决方案
- 云数据的安全性不容忽视
- 线性回归和广义线性回归
- 9个Console命令
- oracle创建视图包含clob字段,报错:数据类型不一致:应为-,但却获得CLOB
- 一位程序员工作10年总结的10条建议
- BMZCTF-MISC(一) WriteUp
- java.lang.IllegalStateException: Failed to convert message:‘‘ to outbound message.
- 开篇词 | 程序员的成长课
- 计算机英语构词法,计算机专业英语的构词方法
- flutter学习笔记之dart(转载至B站up主筱筱知晓的大地老师)
- python中temp的用法_python temp是什么
- SaaS 软件开发为企业数字化转型赋能
- Lintcode 4 Ugly Number II
- 100-days: thirteen
- office 2007 1706错误解决办法