当前位置: 首页 > news >正文

python小实验(根据莫烦python视频)


print(‘apple’)
print(apple)

a,b,c=1,2,3
print(‘a,b,c=’)
print(a,b,c)

自变量定义&d打印

”’
阿斯达斯
”’

循环实验,按顺序打印0-9;注意,while下面必须要比while后一格

condition=0
while condition<10:
print(‘condition=%s’ %condition)
condition+=1

for循环打印1-10,i为受体,即每次的list元素会逐一放到i中打印出来

list=[1,2,3,4,5,6,7,8,9,10]
for i in list:
print(‘i=%s’ %i)
print(‘end counting’)

for range 使用方法 range(起始位,<最大数值(到不了该数值),步长)

for j in range(0,11,2):
print(‘j=%s’ %j)

print(‘end counting’)

if (else) 使用方法,可以搭配for使用限制其范围输出 1—10 仅输出前四个

x=0
list=[1,2,3,4,5,6,7,8,9,10]
for p in list:
print(‘p=%s’ %p)
x+=1
if x==4:
print(‘end counting’)
break
else:
print(‘continue p counting’)

def 定义函数accumerate=加法 saleCar()卖车

def acc(a,b):
print(‘this is a function’)
c=a+b
print(‘c=’,c)
def saleCar(price,color,brand,is_sec_hand):
print(‘price=’,price,
‘color=’,color,
‘brand=’,brand,
‘is sec hand?=’,is_sec_hand,)

saleCar(price=10000,color=’red’,brand=’TOYOTA’,is_sec_hand=’TURE’)

定义全局和局部变量

def fun():
a=10
print(a)
return a+100

#局部-全局 A&a past 为全局 a son 为局部
A=100
a=0
print(A)
print(‘a past=’,a)
def fun1():
a=20
print(‘a son=’,a)
return a+A
print(‘a global=’,a)
print(‘fun1()=’,fun1())
print(‘a past=’,a)

读写文件

text=’This is my first test. This is the second line. This the third ’
print(text) # 无换行命令

“””
This is my first test. This is the second line. This the third
“”“

text=’This is my first test.\nThis is the second line.\nThis the third line’
print(text) # 输入换行命令\n,要注意斜杆的方向。注意换行的格式和c++一样

my_file=open(‘e:\demo\MyFile.txt’,’w’) #用法: open(‘绝对路径文件名’,’形式’), 其中形式有’w’:write;’r’:read.
my_file.write(text) #该语句会写入先前定义好的 text
my_file.close() #关闭文件

file = open(‘e:\demo\my file.txt’,’r’)

while 1: #读文件 快速
lines = file.readlines()
if not lines:
break
for line in lines:
print(line)
pass

`

相关文章:

  • 如何在多文本中提取指定数据,并按时间命名文件名
  • 数理统计(一)-期望和方差
  • 数理统计(二)-数据的类型和基本概念
  • 通过matlab实现正交表
  • 基于TP-LINK(AC1200)主路由器+FAST(FWR303)副路由器的桥接(中继)信号放大
  • matlab怎么找出一串数中的连续的数字
  • C#+VTK+VS2010环境配置---方法1
  • C#+VTK+VS2010环境配置--方法2
  • Qt Creator下载和安装(详细教程)
  • java绘制图片验证码两种方式实现,点击【图片】刷新和点击【看不清换一张】刷新
  • java 验证码实现
  • Servlet中doGet和doPost方法有何区别?
  • form表单
  • 关于struts2中ActionContext的实现原理
  • Struts2 form表单的action和onsubmit事件说明
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • Dubbo 整合 Pinpoint 做分布式服务请求跟踪
  • dva中组件的懒加载
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • ESLint简单操作
  • Python打包系统简单入门
  • Shell编程
  • 阿里云前端周刊 - 第 26 期
  • 关于extract.autodesk.io的一些说明
  • 诡异!React stopPropagation失灵
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 开源SQL-on-Hadoop系统一览
  • 数据仓库的几种建模方法
  • 探索 JS 中的模块化
  • 通过调用文摘列表API获取文摘
  • # centos7下FFmpeg环境部署记录
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • #NOIP 2014# day.2 T2 寻找道路
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (TOJ2804)Even? Odd?
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (篇九)MySQL常用内置函数
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (一) storm的集群安装与配置
  • (一)使用IDEA创建Maven项目和Maven使用入门(配图详解)
  • (转)Sql Server 保留几位小数的两种做法
  • (转)一些感悟
  • .Net Memory Profiler的使用举例
  • .net 后台导出excel ,word
  • .Net 路由处理厉害了
  • .net 提取注释生成API文档 帮助文档
  • .Net 应用中使用dot trace进行性能诊断
  • .net中应用SQL缓存(实例使用)
  • /run/containerd/containerd.sock connect: connection refused
  • @Bean有哪些属性
  • [ web基础篇 ] Burp Suite 爆破 Basic 认证密码
  • [\u4e00-\u9fa5] //匹配中文字符