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章的更多相关文章

  1. #Python编程从入门到实践#第四章笔记

    #Python编程从入门到实践#第四章笔记   操作列表 ​​​1.遍历列表 使用for循环,遍历values列表 for value in values: print(value) 2.数字列表 使 ...

  2. 《Python编程从入门到实践》第二章_变量和简单数据类型

    什么是变量呢? 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Pyth ...

  3. #Python编程从入门到实践#第三章笔记

      列表简介 ​​​1.什么是列表 列表:由一系列按也顶顺序排列的元素组成.元素之间可以没有任何关系. 列表:用方括号[]表示,并用逗号分隔其中元素.名称一般为复数 2.访问元素 (1)列表是有序集合 ...

  4. Python编程从入门到实践笔记——异常和存储数据

    Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...

  5. Python编程从入门到实践笔记——文件

    Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...

  6. Python编程从入门到实践笔记——类

    Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...

  7. Python编程从入门到实践笔记——函数

    Python编程从入门到实践笔记——函数 #coding=gbk #Python编程从入门到实践笔记——函数 #8.1定义函数 def 函数名(形参): # [缩进]注释+函数体 #1.向函数传递信息 ...

  8. Python编程从入门到实践笔记——用户输入和while循环

    Python编程从入门到实践笔记——用户输入和while循环 #coding=utf-8 #函数input()让程序暂停运行,等待用户输入一些文本.得到用户的输入以后将其存储在一个变量中,方便后续使用 ...

  9. Python编程从入门到实践笔记——字典

    Python编程从入门到实践笔记——字典 #coding=utf-8 #字典--放在{}中的键值对:跟json很像 #键和值之间用:分隔:键值对之间用,分隔 alien_0 = {'color':'g ...

随机推荐

  1. 删除Win10资源管理器中的3D对象/音乐/视频文件夹

    Win10如何删除资源管理器中的3D对象/音乐/视频等文件夹?使用Win10系统的用户都知道,打开此电脑之后,资源管理上面会显示文档/音乐/视频等7个文件夹,一些用户认为很少使用到它们,想要除之而后快 ...

  2. Arrays类的运用,二分法,数组的复制,命令行参数的运用,二维数组,Object,equals

    /*Arrays jdk中为了便于开发,给开发者提供了Arrays类, 其中包含了很多数组的常用操作.例如快速输出.排序.查找等.*/ import java.util.Arrays; public ...

  3. pycharm远程调试服务器

    1.下载专业版pycharm并激活 https://blog.csdn.net/weixin_39332299/article/details/79692283 2.创建项目,设置解释器时,选择SSH ...

  4. css @import 导入文件

    导入另一个css文件 例如 <style type="text/css"> @import url(css/main.css); //导入css目录下的main.css ...

  5. 论文阅读笔记五十四:Gradient Harmonized Single-stage Detector(CVPR2019)

    论文原址:https://arxiv.org/pdf/1811.05181.pdf github:https://github.com/libuyu/GHM_Detection 摘要 尽管单阶段的检测 ...

  6. C++11 带来的新特性 (4)—— 匿名函数(Lambdas)

    1 语法 Lambdas并不是新概念,在其它语言中已经烂大街了.直接进入主题,先看语法: [ captures ] ( params ) specifiers exception attr -> ...

  7. haproxy代理配置段参数设定

    代理配置段:有四个配置段 default:设定默认参数, frontenf:前端服务器的设定 backend:后端服务器的设定 listening:是设定前端和后端一一对应的设定 参数: 1bind: ...

  8. ssm简单搭建

    目录结构 1.web.xml配置文件 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns ...

  9. UOJ#266. 【清华集训2016】Alice和Bob又在玩游戏 博弈,DSU on Tree,Trie

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ266.html 题解 首先我们可以直接暴力 $O(n^2)$ 用 sg 函数来算答案. 对于一个树就是枚举 ...

  10. fine-tuning 两阶段模型

    目前大部分的nlp任务采用两阶段的模型,第一阶段进行预训练,一般是训练一个语言模型.最出名的是BERT,BERT的预训练阶段包括两个任务,一个是Masked Language Model,还有一个是N ...