目录
前言
一、基础学习
1.加了引号的字符都被认为是字符串?
2.类型
3.列表
4.remove写值删
5.逻辑运算符or的优先级更高
总结
前言
一个Python小白的学习经历
提示:以下是本篇文章正文内容,下面案例可供参考
一、基础学习
1.加了引号的字符都被认为是字符串?
单引号&双引号无区别——考虑单双配合 多引号用于多行字符串
>>> msg = """Evan is a handsome boy
... I like he
... wow
... .
... """
>>> msg
'Evan is a handsome boy\nI like he\nwow\n.\n'
>>> print(msg)
Evan is a handsome boy
I like he
wow
.
2.类型
>>> type(msg)
<class 'str'>
字符串可拼接(仅限于字符串本身)
+
>>> name
'Evan'
>>> hometown = 'gansu'
>>> name + hometown
'Evangansu'
*
>>> name * 3
'EvanEvanEvan'
3.列表
>>> names = []
>>> type(names)
<class 'list'>
>>> names = ["a","b","c","d"]
>>> names[3]
'd'
列表的修改
>>> names[1] = "K"
>>> names
['a', 'K', 'c', 'd']
列表的追加
>>> names.insert(3,"P")
>>> names
['a', 'K', 'c', 'P', 'd']
>>> names.append("F")
>>> names
['a', 'K', 'c', 'P', 'd', 'F']
列表的删除
>>> del names[3]
>>> names
['a', 'K', 'c', 'd', 'F']
4.remove写值删
>>> names.remove("a")
>>> names
['K', 'c', 'd', 'F']
检查是否在列表里
>>> "K" in names
True
5.逻辑运算符 or的优先级更高
总结
第一次在CSDN写笔记,喜欢这个节奏,继续下去!!!
?
|