编程语言
首页 > 编程语言> > python02-数据类型

python02-数据类型

作者:互联网

身份验证

三元运算

数据类型-列表

数据类型-元组

name = ("apple","bob")
print(name[1])

bob
name = ("apple","bob",["张三","李四"])
name[2][0]="王五"
print(name)

('apple', 'bob', ['王五', '李四'])

数据类型-字符串

s = "Hello,Eva! How are you?"
print(s[1])

e
s = "Hello,Eva! How are you?"
print(s[::3])

HlE!oa u
name = "jack\t\n"
print(name)
print("=========")
name1 = r"jack\t\n"
print(name1)


jack	

=========
jack\t\n

name  = "GuanSuo"
print(name.center(20, '-'))


------GuanSuo-------
name  = "GuanSuoasbbb"
print(name.count("a"))
print(name.count("a", 1, 4))


2
1
name  = "GuanSuoasbbb"
print(name.find("a"))
print(name.find("a", 2)) #从2开始找

2
2
#两种方法实现
s = "My name is %s  , i am %s years old" %("alex",23) #1
print(s)

s1 = "My name is {0}  , i am {1} years old"  #2
print(s1.format("gs", 22))

s2 = "Welcome {name} to Apeland , you are No.{user_num} user."
print(s2.format(user_num=24, name="张三"))



My name is alex  , i am 23 years old
My name is gs  , i am 22 years old
Welcome 张三 to Apeland , you are No.24 user.
name = ["shangsan","lisi","Wanger"]
print("? ".join(name))

shangsan? lisi? Wanger
name1 = "ASDasd"
print(name1.lower())

asdasd
str.ljust(width[, fillchar])

width -- 指定字符串长度。
fillchar -- 填充字符,默认为空格。
str = "this is string example....wow!!!"
print(str.ljust(50, '0'))

this is string example....wow!!!000000000000000000
000000000000000000this is string example....wow!!!
str1 = "   Welcome to Guru99!    "
after_strip = str1.strip()
print(after_strip)


Welcome to Guru99!
a = "My score is 580, not 580 very good."
print(a.replace("580", "666"))
print(a.replace("580", "666",1))     # 改一次
My score is 580, not 580 very good.
My score is 666, not 580 very good.
a = "aaaaa bbbbb."
print(a.split())
print(a.split("a",2))


['aaaaa', 'bbbbb.']
['', '', '', '', '', ' bbbbb.']
a = "aaaaa BBBbb"
print(a.swapcase())


AAAAA bbbBB
a = "aaaaa BBBbb"
print(a.upper())


AAAAA BBBBB
a = "aaaaa BBBbb"
print(a.casefold())

aaaaa bbbbb
a = "aaaaa BBBbb"
print(a.capitalize())

Aaaaa bbbbb
str = "hello,i love python"
print("1: ",str.startswith("h"))
print("2:",str.startswith("l",2,10))# 索引 llo,i lo 是否以“n”结尾。
print("3:",str.startswith(""))#空字符
print("4:",str[0:6].startswith("h")) # 只索引 hello,
print("5: ",str[0:6].startswith("e"))
print("6: ",str[0:6].startswith(""))
print("7:",str.startswith(("h","z")))#遍历元组的元素, 存在即返回True,否者返回False print("8:",str.startswith(("k","m")))

1:  True
2: True
3: True
4: True
5:  False
6:  True
7: True  

数据类型-字典

标签:name,数据类型,王二,sdf,李四,python02,print,bob
来源: https://www.cnblogs.com/aohongchang/p/16619233.html