首页 > 编程语言 > 详细

python的基本数据类型

时间:2020-07-03 16:53:23      阅读:51      评论:0      收藏:0      [点我收藏+]
‘‘‘
int
str
bool
list 存储大量的数据,用[]来表示
tuple 元组,不可以发生改变,用()来表示,和C++的元组是一样的
dict 字典,保存键值对,一样可以保持大量的数据,和C++的map一样
set 集合,内部数据不可以重复
‘‘‘

 字符串的任何操作都不会改变它本身,所以需要提供另一个字符串来承装

#字符串的截取片段
s1 = input("输入字符串:\n")
a = input("输入开始截取的位置:\n")
b = input("输入结束截取的位置:\n")
a = int(a) - 1
b = int(b)
s2 = s1[a:b]
print(s2)
print(s1[:5]) #默认从开始截取到第5个位置(包括第五个位置)
#字符串首字母大写转化
s1 = "abnddhj"
s2 = s1.capitalize()
print(s1)
print(s2)

#字符串的大小写转化
s3 = "abcABC"
s4 = s3.lower() #字符串的小写转化
s5 = s3.upper() #字符串的大写转化
s6 = s3.swapcase() #大小写互换
print(s3)
print(s4)
print(s5)
print(s6)
#去掉字符串两边的空格
using = input("输入登录用户名").strip() #把输入的字符串去掉空格,只能去掉字符串前后的空格,不能去掉字符串中间的空格
password = input("输入密码").strip() #把输入的密码字符串中的空格去掉,只能去掉字符串前后的空格,不能去掉字符串中间的空格
print(using)
print(password)
if using == "liuwenjie" and password == "123":
    print("登陆成功")
else:
    print("登陆失败")

#去掉字符串两边指定的内容
string = "abcdadcdabcd"
print(string.strip("abcd"))
print(string.strip("abc"))

 

 

python的基本数据类型

原文:https://www.cnblogs.com/boost/p/13229455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!