python 4 -- python数据类型
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python 4 -- python数据类型,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1971字,纯文字阅读大概需要3分钟。
内容图文
简单数据类型
字符串
- 单引号,双引号,三引号括起来的都是字符串
- Python中的字符串有两种索引方式,从左往右以0开始,从右往左以-1开始
>>> a = 'lapland'
>>> print(a[-1])
d
- Python中的字符串不能改变
转义字符串
转义字符 | 含义 |
---|---|
\n | 换行 |
\t | 制表(Tab) |
\r | 回车(Enter) |
\ | 反斜杠 |
’ | 单引号 |
" | 双引号 |
- 前面加r可以取消转义,如下:
>>> print('lapla\nd')
lapla
d
>>> print(r'lapla\nd')
lapla\nd
字符串运算
字符串可以用+运算符连接在一起,用*运算符重复
>>> print('lap'+'land')
lapland
>>> print('bye'*2)
byebye
字符串处理函数
# 我多敲了好多回车...只是为了看得清楚一点
>>> notMe = 'lapland Stark is an elf'
>>> print("source string is ", notMe)
source string is lapland Stark is an elf
>>>
>>> print("swapcase demo", notMe.swapcase(), sep='\t')
swapcase demo LAPLAND sTARK IS AN ELF
>>>
>>> print("upper demo", notMe.upper(), sep='\t')
upper demo LAPLAND STARK IS AN ELF
>>>
>>> print("lower demo", notMe.lower(), sep='\t')
lower demo lapland stark is an elf
>>>
>>> print("title demo", notMe.title(), sep='\t')
title demo Lapland Stark Is An Elf
>>>
>>> print("istitle demo", notMe.istitle(), sep='\t')
istitle demo False
>>>
>>> print("islower demo", notMe.islower(), sep='\t')
islower demo False
>>>
>>> print("capitalize demo", notMe.capitalize(), sep='\t')
capitalize demo Lapland stark is an elf
>>>
>>> print("find demo", notMe.find('r'), sep='\t')
find demo 11
>>>
>>> print("count demo", notMe.count('l'), sep='\t')
count demo 3
>>>
>>> print("split demo", notMe.split(' '), sep='\t')
split demo ['lapland', 'Stark', 'is', 'an', 'elf']
>>>
>>> print("join demo", '.'.join(notMe), sep='\t')
join demo l.a.p.l.a.n.d. .S.t.a.r.k. .i.s. .a.n. .e.l.f
>>>
>>> print("len demo", len(notMe), sep='\t')
len demo 23
整数
整数有不同的进制表示:
0<进制表示><数字> |
进制 |
---|---|
0o | 八进制 |
0x | 十六进制 |
0b | 二进制 |
运算符
运算符 | 描 述 |
---|---|
** | 乘方 |
* | 乘法 |
/ | 除法 标签:,,,,,,, 来源: https://blog.csdn.net/weixin_45494811/article/details/104071078 |
内容总结
以上是互联网集市为您收集整理的python 4 -- python数据类型全部内容,希望文章能够帮你解决python 4 -- python数据类型所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。