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. IntelliJ IDEA 报错:找不到包或者找不到符号

    原因 在网上各种找 https://blog.csdn.net/qq_17213067/article/details/78895302 https://blog.csdn.net/u01398566 ...

  2. js性能的进阶

    为了说明js性能方面的差异用一个简单的例子说明下, <style> #ul1{ padding: 5px; overflow: hidden; } #ul1 li{ list-style: ...

  3. RCNN论文学习

    [Rich feature hierarchies for accurate object detection and semantic segmentation] Abstract     论文的方 ...

  4. 屏蔽eslint代码格式报错

    1.在文件中找到node_modules 2.node_modules文件夹下的eslint-config-standard 3.打开eslint-config-standard文件夹下的eslint ...

  5. python3 集合(set)

    一.定义:集合是一个无序不重复元素序列 语法: #---------------两种写法-------------------------# parame = {value1,value2,value ...

  6. 2018-2019-2 网络对抗技术 20165323 Exp6 信息搜集与漏洞扫描

    一.实验内容 二.实验步骤 1.各种搜索技巧的应用 2.DNS IP注册信息的查询 3.基本的扫描技术 主机发现 端口扫描 OS及服务版本探测 具体服务的查点 4.漏洞扫描 三.实验中遇到的问题 四. ...

  7. MyBatis insert/delete/update 的返回值

    insert,返回值是:新插入行的主键(primary key):需要包含<selectKey>语句,才会返回主键,否则返回值为null. <insert id="inse ...

  8. c++ 开源库介绍和安装

    1 BLAS库 BLAS(Basic Linear Algebra Subprograms)是一组线性代数计算中通用的基本运算操作函数集合.BLAS Technical (BLAST) Forum负责 ...

  9. 使用Kazoo操作ZooKeeper服务治理

    单机服务的可靠性及可扩展性有限,某台服务宕机可能会影响整个系统的正常使用:分布式服务能够有效地解决这一问题,但同时分布式服务也会带来一些新的问题,如:服务发现(新增或者删除了服务如何确保能让客户端知道 ...

  10. VSTO 基础随笔

    1.往组合框添加条目 With Me .ComboBox1.Items .Add( "Ports" ) .Add( "Igor" ) End With 2.文本 ...