Python编程--从入门到实践 Day1 2018-03-19

加入读书读书打卡群好几天了,一直没有动手,从今天开始记录自己的学习过程。先从基础开始,巩固一下自己的基础知识,也慢慢培养自己写东西的习惯。

1.字符串
字符串是 python 数据类型中的一种,由一系列字符组成。由单引号(')或者双引号('')括起。 如:
"This is a string."
'This is also a string.'
字符串对单双引号的支持可以在字符串中包含单引号或者双引号。如:
"hello, 'xiaoming'!"
' "saying", xiaoming'
还可以使用三引号,支持多行。如:
'''python'''

''' I \
like \
python ''' 

2.字符串方法

  • 2.1 修改大小写
    title() , 首字母大写
    upper() , 字符串都大写
    lower(),字符串都==小写
>>> 'hello'.title()
'Hello'

>>> 'hello'.upper()
'HELLO'

>>> 'HELLO'.lower()
'hello'
  • 2.2 合并字符串
    可以使用符号 + 来实现字符串的拼接,
>>> 'hello' + 'world'
'helloworld'
  • 2.3 使用制表符来添加空白
>>> print('\thello,python')
    hello,python

>>> print('hello,\tpython\n\tjava\n\truby\n')
hello,  python
    java
    ruby
  • 2.4 删除空白
>>> 'python '.rstrip()
'python'
>>> ' python'.lstrip()
'python'
>>> ' python '.strip()
'python'

你可能感兴趣的:(Python编程--从入门到实践 Day1 2018-03-19)