Skip to content

Instantly share code, notes, and snippets.

@HKhademian
Created May 5, 2020 19:20
Show Gist options
  • Save HKhademian/f0276d5a0c762dd69eb81ca1576e5f57 to your computer and use it in GitHub Desktop.
Save HKhademian/f0276d5a0c762dd69eb81ca1576e5f57 to your computer and use it in GitHub Desktop.
This file contains console texts wrote and responded in a learning video:
[1, "hi", 'h']
[1, 'hi', 'h']
list1 = []
list2 = [ "red", "blue", "yellow" ]
list2[0]
'red'
list2[2]
'yellow'
list2[3]
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list index out of range
list2[-1]
'yellow'
list2[-2]
'blue'
list3 = list(range(10))
list3[2:5]
[2, 3, 4]
list3[2:5+1]
[2, 3, 4, 5]
list3[2:-1]
[2, 3, 4, 5, 6, 7, 8]
list3[2:]
[2, 3, 4, 5, 6, 7, 8, 9]
list3[-3:]
[7, 8, 9]
list[0:2]
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: 'type' object is not subscriptable
list3[0:2]
[0, 1]
list3[:2]
[0, 1]
a = list3[1:2]
list3[4:1]
[]
list3[4:1:-1]
[4, 3, 2]
list3[:]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list4 = list3
list4
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list4 [0] = 999
list4
[999, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list3
[999, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list5 = list3[:]
list5[0] = 0
list3[::2]
[999, 2, 4, 6, 8]
list3[::-1]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 999]
list3[:] = 1
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: can only assign an iterable
for i in range(10): print(list3[i])
999
1
2
3
4
5
6
7
8
9
for it in list3:
print(it)
999
1
2
3
4
5
6
7
8
9
0 in list3
False
list3[0] = 0
0 in list3
True
list3[0] = 'zero'
list3
['zero', 1, 2, 3, 4, 5, 6, 7, 8, 9]
'zero' in list3
True
0 in list3
False
len(list1)
0
len(list3)
10
len(list2)
3
list3[10] = 'a'
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list assignment index out of range
list3.append('a')
list3.insert(1, 'b')
list3.insert(0, 1374)
list3.remove('zero')
list3.append('x')
list3.append('x')
list3.append('x')
list3.append('x')
list3.remove('x')
list3.pop()
'x'
guests = ['ali' , 'saeed', 'hamid']
guests.pop()
'hamid'
guests.pop()
'saeed'
guests.pop()
'ali'
guests.pop()
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: pop from empty list
del list3[5]
del list3[-1]
del list3[0:5]
del list5[::3]
list3.clear()
del list5[:]
list5 = list(range(1,100,5))
list3 = list5.copy()
typeof(range(10))
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'typeof' is not defined
type(range(10))
<class 'range'>
int('123')
123
list("Hossain")
['H', 'o', 's', 's', 'a', 'i', 'n']
list(range(100,-100,-10))
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, -60, -70, -80, -90]
list( ("a", "b", 3) )
['a', 'b', 3]
t=("a", "b", 3)
t
('a', 'b', 3)
list(t)
['a', 'b', 3]
t=list(t)
list10 = list2 + t
list0 = list2
list2.append(0)
del list5
del t
del list4
del list 3
File "<input>", line 1
del list 3
^
SyntaxError: invalid syntax
del list3
del quests
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'quests' is not defined
del guests
del list1
del list10
list3 = list0 + [ 5, 6, 7 ]
list0[0] = 'RED'
list0.extend([ 5, 6, 7 ])
list3.pop()
7
del list2[0]
list0 .extend([ 0, 1, 0, 2, 3, 0])
list0.count(0)
4
list0.count('RED')
0
list0[::-1]
[0, 3, 2, 0, 1, 0, 7, 6, 5, 0, 'yellow', 'blue']
list0.reverse()
list0.sort()
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'int'
list4 = list (range(100,0, -10))
list4
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
list4.sort()
list4
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
a = ['apple' , '0AD' , 'zera', 'web', 'android']
a
['apple', '0AD', 'zera', 'web', 'android']
a.sort()
a
['0AD', 'android', 'apple', 'web', 'zera']
list3*5
['red', 'blue', 'yellow', 0, 5, 6, 'red', 'blue', 'yellow', 0, 5, 6, 'red', 'blue', 'yellow', 0, 5, 6, 'red', 'blue', 'yellow', 0, 5, 6, 'red', 'blue', 'yellow', 0, 5, 6]
[1,2]*3
[1, 2, 1, 2, 1, 2]
list5 = list3 + list0 + [1300]
list5 = list5 + [2000]
list100 = list5
list5 = list5 + [2000]
list5 += [ 1 ]
l = list5 + []
l.pop()
1
list6=list5
list6 += []
list5.pop()
1
list5.pop()
2000
list5.pop()
2000
list6 = list6 .copy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment