python3学习笔记(二)

2020-04-03  本文已影响0人  壹顾倾城
【本节知识点】:
      字符串输出
      replace
      格式化 %s   {}  format
      字符串切片

1、四种数据结构


004.jpg
>>> list = ['a', 'b', 1, 2, a, ['x', 'y'], ('z','k')]
>>> print(list)
['a', 'b', 1, 2, 'You are my good friend', ['x', 'y'], ('z', 'k')]
>>> print(list[1])
b
>>> print(list[5])
['x', 'y']
>>> print(list[4])
You are my good friend
>>>

2、列表增加、删除


005.jpg
>>>  list.append("bug")
>>> print(list)
['a', 'b', 1, 2, 'You are my good friend', ['x', 'y'], ('z', 'k'), 'bug']
>>> list.remove(list[-1])
>>> print(list)
['a', 'b', 1, 2, 'You are my good friend', ['x', 'y'], ('z', 'k')]

>>> list = [1,2,3]
>>> list.append(3)
>>> print(list)
[1, 2, 3, 3]
>>> list.append("h")
>>> list.append("e")
>>> print(list)
[1, 2, 3, 'h', 'h', 'e']
>>>
>>> list.remove('e')
>>> print(list)
[1, 2, 3, 'h', 'h']
上一篇下一篇

猜你喜欢

热点阅读