最近开始重新回过头来巩固一下python的基础知识,并在此做一些记录以便未来更好的回顾

一、字符串的大小写转换

title()

使用title()方法可以将字符串中每个单词的首字母大写

 name = "hello world"
print(name.title())

运行得到结果:

Hello World

upper()

使用upper()方法可以将字符串中的每一个字母转换为大写

 name = "hello world"
print(name.upper())

运行得到结果:

HELLO WORLD

lower()

使用lower()方法可以将字符串中的所有字母转换为小写

 name = "HELLO WORLD"
print(name.lower())

运行得到结果:

hello world

二、拼接字符串

使用+对字符串进行拼接

 first = "hello"
last = "world"
add = first + " " + last
print(add)

运行后得到结果:

hello world

三、使用制表符和换行符

制表符

制表符可以使用字符组合\t

 print("\tpython")

运行得到结果:

#输出结果前有一个空格
python

换行符

 print("languages:\nPython\nJava")

运行得到结果:

languages:
Python
Java

四、删除空白

删除末尾的空白

使用rstrip()

 name = "python "
print(name.rstrip())

运行得到结果:

python

删除开头的空格

使用lstrip()

 name = " python"
print(name.lstrip())

运行得到结果:

python

同时剔除开头和结尾的空格

使用strip()

 name = " python "
print(name.strip())

运行得到结果:

python

最新文章

  1. win 7下建立FTP
  2. poj2236_并查集_Wireless Network
  3. nginx 启动、重启、关闭
  4. [GodLove]Wine93 Tarining Round #8
  5. 在linux上使用交换文件扩展交换空间
  6. jQuery 2.0.3 源码分析 Deferrred概念
  7. 创建本地Ubuntu镜像
  8. 合并大量txt文件的内容
  9. 使用python网络库下载
  10. Http方式获取网络数据
  11. JSP/Servlet(一)
  12. 【有意思的BUG】分享按钮 分享功能
  13. #include <iostream>与#include <iostream.h>的区别
  14. CSS透明opacity和IE各版本透明度滤镜filter的准确用法
  15. Asp.Net SignalR Hub类中的操作详解
  16. WPF样式中TargetType 属性 (Property) 和 x:Key 属性 (Attribute)
  17. npm install --save 、--save-dev 、-D、-S 的区别
  18. LINUX内核PCI扫描过程
  19. [Swift]JSON字符串与字典(Dictionary)、数组(Array)之间的相互转换
  20. centos6.8安装httpd后无法访问

热门文章

  1. PHP中redis加锁和解锁的简单实现
  2. node的fs模块使用————node
  3. A Tutorial on Using the ALSA Audio API
  4. Linux就该这么学11学习笔记
  5. Informatica参考
  6. springboot打包成jar文件无法正常运行,解决办法已经找到
  7. NOIP2018系列
  8. jQuery给css增加!important
  9. BiNGO的GO分析
  10. 51nod 1605:棋盘问题