python编程从入门到实战1-3章
print('hellow world')
""" 多行注释"""
#大小写
print('i love you')
mssage='hellow world'
print(mssage)
name=('ada lovelace')
print(name.title())
print(name.upper())
print(name.lower())
# 字符串拼接 【建议使用join】
first_name="ada"
last_name="lovelace"
full_name=first_name+" "+last_name
print(full_name)
print("hello,"+full_name.title()+"!")
mssage="Hello,"+full_name.upper()+"!"
print(mssage)
print("\n python\n")
#删除空白 末端rstrip() 前端lstrip.() 两端strip()
favorite_language=' python '
print(favorite_language.rstrip())#末尾
print(favorite_language.lstrip())#前端
print(favorite_language)
print(favorite_language.strip())#两端
print("为了避免语法错误,单双引号适当混合使用(即:系统无法判定结束位置")
#数字
print(2+3)
print(3-2)
print(3/2)
print(2*3)
print(3 ** 2)#平方
print(2+3*4)
print((2+3)*4)
#浮点数和c语言一样
print(3*0.1)
print('结果包含的小数点可能是不确定的')
#使用函数str()避免类型错误 str()
age=23
mssage="happy "+str(age)+"rd brithday"
print(mssage)
#列表
bicycles=['trek','cannondale','redline','specialized']
print(bicycles)
#访问列表元素
print(bicycles[0])
print(bicycles[0].title())
print(bicycles[0].upper())
#访问最后一个元素
print(bicycles[-1])
#使用列表中的值
mssage='My first bicycle was a '+bicycles[0].title()+'.'
print(mssage)
#修改、添加和删除元素(指定)
motorcycles=['honda','yamaha','suzuki']
print(motorcycles)
motorcycles[0]='ducati'
print(motorcycles)
#在列表末尾中添加元素 .append()
motorcycles.append('ducati')
print(motorcycles)
motorcycles=[]
motorcycles.append('honda')
motorcycles.append('yamaha')
motorcycles.append('suzuki')
print(motorcycles)
#在列表中插入元素 .insert()
motorcycles.insert(0,'qianjiang')
print(motorcycles)
#从列表中删除元素
# 1 永久删除知道位置 del
del motorcycles[0]
print(motorcycles)
#使用del得知道位置
# 2 弹出删除法可再次利用(栈) pop()
popde_motorcycles = motorcycles.pop()
print(motorcycles)
print(popde_motorcycles)
#弹出知道位置的元素
first_owned = motorcycles.pop(0)
print(first_owned)
#根据值删除元素
motorcycles=['honda','yamaha','suzuki','ducati']
print(motorcycles)
motorcycles.remove('yamaha')
print(motorcycles)
motorcycles=['honda','yamaha','suzuki','ducati']
print(motorcycles)
too_expensive='ducati'
motorcycles.remove(too_expensive)
print(motorcycles)
#组织列表
#使用sort()队列表进行永久排序 sort()
cars=['bms','audi','toyota','subaru']
print(cars)
cars.sort()
print(cars)
#反向排序 sort(reverse=ture)
cars=['bms','audi','toyota','subaru']
cars.sort(reverse=True) # 大写 直接读源文件修改
print(cars)
#使用sorted()队列表进行临时修改 sorted() 临时修改
print('\nHere is the original list:')
print(cars)
print('here is the sorted list')
print(sorted(cars))
print('the original is not change')
print(cars)
print('临时反向排序向sorted()传递参数reverse=Ture')
print('你不会')
#倒着打印列表 **(不用管顺序)仅仅是反转元元素排列顺序 .reverse()
cars=['bms','audi','toyota','subaru']
print(cars)
cars.reverse() #永久修改元素顺序 想要恢复仅仅需再次倒转即可
print(cars)
#确定列表长度(即元素个数)
cars=['bms','audi','toyota','subaru']
len(cars)
print(len(cars))
#使用列表时候避免索引出错 元素开头是0
#访问最后一个元素时候用-1 仅当列表为空时候 这种访问会出错
python编程从入门到实战1-3章的更多相关文章
- #Python编程从入门到实践#第四章笔记
#Python编程从入门到实践#第四章笔记 操作列表 1.遍历列表 使用for循环,遍历values列表 for value in values: print(value) 2.数字列表 使 ...
- 《Python编程从入门到实践》第二章_变量和简单数据类型
什么是变量呢? 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Pyth ...
- #Python编程从入门到实践#第三章笔记
列表简介 1.什么是列表 列表:由一系列按也顶顺序排列的元素组成.元素之间可以没有任何关系. 列表:用方括号[]表示,并用逗号分隔其中元素.名称一般为复数 2.访问元素 (1)列表是有序集合 ...
- Python编程从入门到实践笔记——异常和存储数据
Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...
- Python编程从入门到实践笔记——文件
Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...
- Python编程从入门到实践笔记——类
Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...
- Python编程从入门到实践笔记——函数
Python编程从入门到实践笔记——函数 #coding=gbk #Python编程从入门到实践笔记——函数 #8.1定义函数 def 函数名(形参): # [缩进]注释+函数体 #1.向函数传递信息 ...
- Python编程从入门到实践笔记——用户输入和while循环
Python编程从入门到实践笔记——用户输入和while循环 #coding=utf-8 #函数input()让程序暂停运行,等待用户输入一些文本.得到用户的输入以后将其存储在一个变量中,方便后续使用 ...
- Python编程从入门到实践笔记——字典
Python编程从入门到实践笔记——字典 #coding=utf-8 #字典--放在{}中的键值对:跟json很像 #键和值之间用:分隔:键值对之间用,分隔 alien_0 = {'color':'g ...
随机推荐
- 024_mac配置屏保命令
注意吃饭等离开工位的时候养成随时开启屏保的功能,养成信息保护的好习惯,mac如何配置屏幕保护呢? 一. 通过mac"设置"里的"Desktop & Screen ...
- ubuntu命令安装
1.当make时,发现没有对应的命令: apt-get install build-essential 安装工具,可解决这个问题
- 移动端右侧导航 显示隐藏js
transform与fixed影响 html按钮 <span class="nav-btn"></span> <span class="cl ...
- MySQL---DDL+DQL---(四)
三.对数据库表记录进行操作(修改DDL) 1.插入记录:insert 语法:insert into 表 (列名1,列名2,列名3..) values (值1,值2,值3..);--向表中插入某些列in ...
- http 响应状态码介绍
- 数据库根据id排序
select * from 表名 order by id 根据 id 从小到大排序
- swoole 版本查看
php --ri swoole php --ri swoole | grep Version 查看swoole版本 php -m | grep swoole 查看swoole拓展是否安装成功(ph ...
- VisualVM远程监控Java
1.服务器启动jstatd服务设置: jstatd将使用RMISecurityPolicy,并且需要指定安全策略文件. 安全策略文件必须符合安全策略语法,通过命令 jstatd -J-Djava.se ...
- @angular/cli (angular脚手架) 如何降级
1.卸载 npm uninstall -g @angular/cli 2.清除缓存 npm cache verify 3.查看是否卸载成功 ng v //如果显示ng 不是内部或外部的指令 则证明卸载 ...
- qqluxc
因为现在noi/noip都是无限栈 noi-linux开栈指令 ulimit -s 102400 这个是100mb 平衡树*2 维护序列 翻转 平衡树+1 维护区间+* t了3个点.. 注意打完标记 ...