# 0 1 2 3 4 5 6
my_list = [1, 4, 3, 10, 42, 3, 1000]
my_list
[1, 4, 3, 10, 42, 3, 1000]
my_list[5]
3
my_list[0]
1
my_list[1]
4
my_list[1] = 100
my_list
[1, 100, 3, 10, 42, 3, 1000]
len(my_list)
7
my_list[len(my_list) - 1]
1000
my_list[-1]
1000
my_list[-2]
3
my_list[1:4] # срез
[100, 3, 10]
# первый элемент включается, последний — не включается
my_list[2:]
[3, 10, 42, 3, 1000]
my_list[:4]
[1, 100, 3, 10]
first = [1, 2, 3]
second = [10, 23, 15]
new_list = first + second
new_list
[1, 2, 3, 10, 23, 15]
first
[1, 2, 3]
second
[10, 23, 15]
my_list
[1, 100, 3, 10, 42, 3, 1000]
my_list.append(123)
my_list
[1, 100, 3, 10, 42, 3, 1000, 123]
my_list.extend([45, 123, 87])
my_list
[1, 100, 3, 10, 42, 3, 1000, 123, 45, 123, 87]
new_list = my_list.append(1981)
print(new_list)
None
super_list = [12, "Hello", 12.34]
super_list
[12, 'Hello', 12.34]
s = "Hello, world! This is a test."
s.split()
['Hello,', 'world!', 'This', 'is', 'a', 'test.']
s
'Hello, world! This is a test.'
words = s.split()
words
['Hello,', 'world!', 'This', 'is', 'a', 'test.']
type(words)
list
s.split("!")
['Hello, world', ' This is a test.']
words = s.split
words
<function str.split(sep=None, maxsplit=-1)>
words = s.split()
words
['Hello,', 'world!', 'This', 'is', 'a', 'test.']
new_words = ["One", "two", "three"]
", ".join(new_words)
'One, two, three'
new_words
['One', 'two', 'three']
s = ", ".join(new_words)
s
'One, two, three'
"!!!".join(new_words)
'One!!!two!!!three'
"".join(new_words)
'Onetwothree'
str(12)
'12'
x = 12
str(x) * 10
'12121212121212121212'
" -- ".join([1, 2, 3])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-71-7848c2bf2125> in <module> ----> 1 " -- ".join([1, 2, 3]) TypeError: sequence item 0: expected str instance, int found
# Забегу вперёд
numbers = [1, 2, 3]
" -- ".join(map(str, numbers))
'1 -- 2 -- 3'
# map(str, [1, 2, 3]) — грубо говоря, то же самое, что [str(1), str(2), str(3)]
my_list = [1, 2, 3]
new_list = my_list
my_list.append(100)
my_list
[1, 2, 3, 100]
new_list
[1, 2, 3, 100]
a = 10
b = a
a = a + 20
a
30
b
10
my_list = [1, 2, 3]
new_list = my_list.copy()
my_list.append(100)
my_list
[1, 2, 3, 100]
new_list
[1, 2, 3]
new_variant = my_list.append(100)
print(new_variant)
None