Python知识点1——基础

Python字符串

1.用引号引起来的都叫字符串,引号可以是单引号,也可以是双引号,可以 在字符串中添加引号和撇号

name='add, peace'
print(name.title(), name)

name="add, peace"
print(name.upper(), name)

spstr="asd, 'asdgf'"
print(spstr)

spstr2="python's"
print(spstr2)

spstr3='this is "python"'
print(spstr3)

 

2.拼接字符串

Python使用+来拼接字符串

print('hello '+name.title()+" !!")

 

3.删除字符串中的空白

lstrip():删除左侧空白

rstrip():删除右侧空白

strip():删除两侧空白

spacestr=" qwe ert "
print(spacestr.lstrip(),spacestr.rstrip(),spacestr.strip())

 

乘方运算

print(3**5)

 

str函数

该函数用于将非字符串类型转为字符串类型

print(str(1.23456), str(True))

参考书籍:《Python编程从入门到实践》

欢迎大家评论交流,作者水平有限,如有错误,欢迎指出

发布了7 篇原创文章 · 获赞 9 · 访问量 8641

猜你喜欢

转载自blog.csdn.net/Master_Cui/article/details/105157298