python学习日志 20.1.30

1、bool(非零数)为true
bool(0)为false
bool(‘非空字符串’)为true
bool(’’)为false
bool([非空列表])为true
bool([])为false
bool({非空}为true
bool({})为false
2、数字+后缀 j 表示复数
3、单引号,双引号,三引号
单引号,双引号均可用于表示字符串 ‘hello world’、"hello world"均正确
但当字符串中有引号出现时,同时运用两种字符串才可正确表示出字符串 'let’s go’错误
"let’t go"正确
'let\'s go’也正确
(在IDLE中)当字符串跨行且不含有转义字符\n时,可用三引号(单双引号均会报错),也可以运用单双引号,但须在换行处添加 \
4、转义字符
\n 换行
’ 单引号
\t 横向制表符
\r 回车
\ 反斜杠
5、在字符串前(引号前)加r后,普通字符串就变为原始字符串(意味反斜杠失效)
6、字符串的运算

>>> "hello"+"world"
'helloworld'
>>> "hello"*3
'hellohellohello'
>>> 'hello'*'world'
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    'hello'*'world'
TypeError: can't multiply sequence by non-int of type 'str'

7、获取字符串中的某个字符

>>> 'hello world'[0]
'h'
>>> 'hello world'[1]
'e'
>>> 'hello world'[2]
'l'
>>> 'hello world'[-1]
'd'
>>> 'hello world'[-2]
'l'
>>> 'hello world'[-3]
'r'

8、获取字符串中的一组字符

>>> 'hello world'[0:4]
'hell'
>>> 'hello world'[0:5]
'hello'
>>> 'hello world'[0:-1]
'hello worl'
>>> 'hello world'[5:-6]
''
>>> 'hello world'[5:-7]
''
>>> 'hello world'[8:20]
'rld'
>>> 'hello world'[8:]
'rld'
>>> 'hello world'[:-1]
'hello worl'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值