f=str(5.1)
print(type(f))
print(f)
输出为
5.1
a=""
for i in range(10):
a+="sex"
print(a)
li=[]
for i in range(10):
li.append("sex")
b="$".join(li)
print(b)
输出为
sexsexsexsexsexsexsexsexsexsex
sex$sex$sex$sex$sex$sex$sex$sex$sex$sex
str3 = "aaa_333"
str4 = "aaa_333"
l=str3 is str4 #比较的是对象的地址
print(l)
print(id(str3),id(str4))
j=(str3==str4) #==比较的是对象的值
print(j)
str5="asdfg"
h="a" in str5 #成员操作符in
print(h)
输出为
True
42128136 42128136
True
True
str9="$$$axdS$"
str10=str9.strip("$")
print(str10)
输出为
axdS
str3="名字是:{name},年龄是:{age}"
str4=str3.format(name="赵薇",age=45)
print(str4)
输出为
名字是:赵薇,年龄是:45
str3="名字是:{0},年龄是:{1:$^8}"
str4=str3.format("赵薇",45)
print(str4)
输出为
名字是:赵薇,年龄是:$$$45$$$
def fun2(lst):
lst[0] = 5
print(lst)
lst1=list(range(5))
print(lst1)
fun2(lst1)
print(lst1)
输出为
[0, 1, 2, 3, 4]
[5, 1, 2, 3, 4]
[5, 1, 2, 3, 4]
a="to be or not be"
x=a.split('be')
print(x)
输出为
['to ', ’ or not ', ‘’]
str1="abcdefghijklmn"
str2=str1[1:7:2]
print(str2)
输出为
bdf
大小写转换 capitalize\title\upper\lower\swapcase
import io
str1="loveyou"
sio=io.StringIO(str1)
print(sio.getvalue())
sio.seek(3)
sio.write("m")
print(sio.getvalue())
输出为
loveyou
lovmyou
str2=ord('A')
str3=chr(66)
print(str2)
print(str3)
输出为
65
B
str4=0b11001
str5=0b01000
str6=str4|str5#或操作
print(str6)
print(bin(str6))
print(bin(str4^str5))#与操作
a=3
b=a<<2#左移一位相当于成以2,左移两位相当于乘以4
c=a>>2
print(b)
print(c)
str7="stx"
print(str7*3)
输出为
0b11001
0b10001
12
0
stxstxstx