码迷,mamicode.com
首页 > 编程语言 > 详细

Python编程从入门到实践-第2章-字符串

时间:2018-10-28 16:02:44      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:bsp   ring   print   int   ace   编程   rip   lower   javascrip   

一、字符串:一系列字符,python中用一号括起来的即为字符串,可单可双

"This is a string."
This is also a string.

 

#引号灵活性的作用:可在字符串中包含引号和撇号

I told my friend,"python is my favorite language!"
"the language ‘Python‘ is named after Monty Python,not the snake."

 

#1.使用方法修改字符串大的小写

name = "ada lovelace"
print(name.title())

name = "ada lovelace"
print(name.upper())

name = "ada lovelace"
print(name.lower())

 

#2.合并(拼接)字符串

first_name = ada
last_name = lovelace
full_name = first_name +   +last_name

print(full_name)

print ("Hello," + full_name.title() + "!")

message = "Hello," + full_name.title() + "!"
print (message)

 


#3.制表符或换行符添加空白
#制表符:\t

print (python)
print (\tpython)

 

#换行符:\n

print (python)
print (\npython)
print (Languages:\nPython\nC\nJavaScript)

 

 

 

#同时使用制表符和换行符
print (‘Languages:\n\tPython\n\tC\n\tJavaScript‘)


#4.删除空白:rstrip,lstrip,strip
#rstrip:删除右侧空白

#lstrip:删除左侧空白
#strip:删除两侧空白

favorite_language = python 
print (favorite_language)

favorite_language = python 
print (favorite_language.rstrip())


favorite_language = python 
favorite_language = favorite_language.rstrip()
print (favorite_language)

 

favorite_language =  python 
print (favorite_language.rstrip())
print (favorite_language.lstrip())
print (favorite_language.strip())

 

Python编程从入门到实践-第2章-字符串

标签:bsp   ring   print   int   ace   编程   rip   lower   javascrip   

原文地址:https://www.cnblogs.com/Hermione74/p/9865592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!