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. org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0

    注:本文来源于<org/eclipse/jetty/server/Handler : Unsupported major.minor version 52.0> Exception in ...

  2. 3. ORACLE DATAGUARD 进程

    欢迎指正与讨论. 3.1 主库 LNS LNS:一般理解为log network serviceLNS 进程负责将主库redo传输到备库.在11gR1及之前版本进程命名为LNSn,其负责ASYNC和S ...

  3. springboot整合mybatis开发

    1创建项目,在启动类上添加映射扫描注解 2导入依赖,添加mybatis generator自动生成代码插件 <!-- mybatis generator 自动生成代码插件 --> < ...

  4. vapor 生成xcode project 产生的错误解决方式

    运行vapor xcode时报错: Could not generate Xcode project: error: terminated(72): xcrun --sdk macosx --find ...

  5. DDD - 概述 - 聚合 (三)

    不要再看那些理论啦,说的云里雾里的,绕到你怀疑人生 一句话概括聚合创建:聚合的一致性决定了聚合边界的确定,决定了聚合对象的创建.所谓的一致性即事务的一致性,细化就是 立即性和原子性.

  6. *CTF 2019 quicksort、babyshell、upxofcpp

    这次参加比赛总共出了三道,有两道队友都先交了,还是tcl,heap_master卡了差不多一天没解决....还是记录一下出的题目吧 quicksort 题目大体流程就是输入要输入的数字数量,然后输入数 ...

  7. django-celery配置

    1.项目启动顺序: 启动项目: python manage.py runserver 启动celery beat python manage.py celery beat 启动celery worke ...

  8. I - Infinite Improbability Drive

    I - Infinite Improbability Drivehttp://codeforces.com/gym/241750/problem/I不断构造,先填n-1个0,然后能放1就放1,最后这个 ...

  9. ubuntu频繁出现 安装包依赖关系

    折腾了一下午,还差点重装一次,最后记下解决办法,引以为戒! 第一步,备份官方的默认源 避免自己手贱操作失误,重装系统太费时间 cp /etc/apt/sources.list /etc/apt/sou ...

  10. 创建线程的第三种方式——使用Callable接口

    Callable是类似于Runnable的接口,实现Callable的类和实现Runnable的类都是可被其他线程执行的任务. 优点:有返回值 缺点:实现繁琐 简单实现: CallableAndFut ...