1.元组

#只读列表,元组,当希望生成后不被修改则用元组
r=(1,2,3,4,5)

元组

2.字符串,python字符串操作非常丰富,编程时可先查询python本身是否已设计了相关函数

 #移除空白
username='alex '
if username.strip()=='alex':
print('welcome')
#如需移除其它字符,比如:\n,就用strip('\n')的方式 #分割
names='alex,jack,rain'
print("names====",names)
name2=names.split(',')
print("name2====",name2)
#将列表用|连起来
name3="|".join(name2)
print("name3=",name3) #格式化
msg="hello,{name},it's been a long {age} since last time spoke"
print("msg===",msg)
msg2=msg.format(name='Minghu',age=333)
print("msg2===",msg2) msg3="haha {0},dddd {1}"
print("msg3==",msg3)
print("format msg3==",msg3.format('Alex',33)) #切片
name='alex Li'
print(name[2:4])
print(name.center(40,'-')) #其它操作
name='alex li'
print("name==",name)
print ("if space in name",(' ' in name))#有没有空格
print(name.capitalize())#首字母大写
print(name.find('l'))#如脜在返回下标,不存在返回-1 age=input("your age:")
if age.isdigit():
age=int(age)
else:
print("invalid data type") print(name.isalnum())
print(name.startswith('al'))
print(name.endswith('li'))
print(name.upper())

一些基本操作

												

python学习day4--python基础--元组,字符串的更多相关文章

  1. Python学习笔记-Day2-Python基础之字符串操作

    字符串的常用操作包括但不限于以下操作: 字符串的替换.删除.截取.复制.连接.比较.查找.分割等 这里将对字符串的内置操作方法进行总结归纳,重点是以示例的方式进行展示. 使用type获取创建对象的类 ...

  2. python学习日记(基础数据类型及其方法01)

    数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...

  3. Python学习day11-函数基础(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. Python学习课程零基础学Python

    python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...

  5. Python学习2-列表和元组

    Python学习2-列表和元组 标签(空格分隔): 列表 元组 在Python中,最基本的数据结构是序列(sequence).序列中的每个元素被分配一个序号--即元素的位置,也称为索引.索引从0开始. ...

  6. Python学习系列(三)(字符串)

    Python学习系列(三)(字符串) Python学习系列(一)(基础入门) Python学习系列(二)(基础知识) 一个月没有更新博客了,最近工作上有点小忙,实在是没有坚持住,丢久又有感觉写的必要了 ...

  7. Python学习day12-函数基础(2)

    <!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...

  8. Python学习day05 - Python基础(3) 格式化输出和基本运算符

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  9. Python学习笔记之基础篇(-)python介绍与安装

    Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...

  10. Python学习day16-模块基础

    <!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...

随机推荐

  1. MsSQL的游标的综合运用

    USE [ChiefWMS]GO/****** Object: StoredProcedure [dbo].[WMS_Check] Script Date: 04/05/2016 09:51:13 * ...

  2. Enterprise Library 4 数据访问应用程序块

    Enterprise Library 数据访问应用程序块简化了实现常规数据访问功能的开发任务.应用程序可以在各种场景中使用此应用程序块,例如为显示而读取数据.传递数据穿过应用程序层( applicat ...

  3. 单个SWF文件loading加载详解(转)

    通过带宽查看器,可以看到SWF中每帧所占带宽状况.另外,我们还可以在Flash发布设置中,选择生成体积报告. 勾选这一项之后,发布flash时,会自动在fla目录中生成一个名为”文件名 Report. ...

  4. Amazon DynamoDB 概览

    1. 什么是Amazon DynamoDB DynamoDB 是一种快速.全面受管的 NoSQL 数据库服务,它能让用户以简单并且经济有效地方式存储和检索任何数据量,同时服务于任何程度的请求流量.所有 ...

  5. linux php开启openssl

    1.测试openssl是否安装查看版本  openssl version查看路径  which openssl2.因为要扩展php扩展模块,所以要通过phpize可以建立php的外挂模块find / ...

  6. ValueBar

    https://github.com/PhilJay/ValueBar

  7. HBuilder:最快的Web开发IDE

    这里给大家介绍一个个人觉得最好用的web开发工具:Hbuilder. HBuilder是DCloud推出的一款支持HTML5的Web开发IDE.快,是HBuilder的最大优势,通过完整的语法提示和代 ...

  8. 解决Server Error in '/' Application.方法!

    <!-- Web.Config Configuration File --> <configuration>      <system.web>           ...

  9. Shell脚本调试工具set

    可以使用set命令的x选项,显示所有命令执行及变量值的变化过程等. 具体使用方法:首先使用set -x开启调试模式,最后使用命令set +x关闭调试模式. 一个简单示例演示如何使用set命令进行脚本调 ...

  10. 奇异值分解(SVD) --- 几何意义

    原文:http://blog.sciencenet.cn/blog-696950-699432.html PS:一直以来对SVD分解似懂非懂,此文为译文,原文以细致的分析+大量的可视化图形演示了SVD ...