python小实验(根据莫烦python视频)
来源:互联网 发布:三亚南山寺旅游数据 编辑:程序博客网 时间:2024/06/05 06:24
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
`
- python小实验(根据莫烦python视频)
- Python开发简单爬虫(根据慕课网视频课程整理)
- Python(一)初学小实验
- Python基础 print()莫烦视频
- python根据url地址下载小文件
- python 类方法(classmethod)小实验代码
- python小实验(1):字符串处理
- python小练习:网络视频下载
- Python爬虫-爬取腾讯小视频
- python视频
- python视频
- python dict 字典 以及 赋值 引用的一些小实验
- Python小实验——向类传递参数
- 腾讯文智自然语言处理-分词API Python小实验
- python小爬虫SendKey自动刷博刷视频外挂
- python小爬虫SendKey自动刷博刷视频外挂
- 小甲鱼python视频的笔记【斜杠派】
- Python Tips(Python小知识点)
- Leetcode: 454. 4Sum II
- JAVA第三次作业(1)
- 常见 Web 攻击介绍
- AttributeError: module 'tensorflow' has no attribute 'select'
- Spring 事务管理学习总结篇
- python小实验(根据莫烦python视频)
- 关于“Error: "const char *" 类型的实参与 "LPCWSTR"类型的形参不兼容”错误的解决方案
- 数组的简单总结
- 洛谷 p1197 [JSOI2008]星球大战(并查集)
- 算法分析与设计课程作业第五周#1
- jQuery插件开发细节
- 写给现在的自己
- python学习:参考
- leetcode 639. Decode Ways II