Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> break
- SyntaxError: 'break' outside loop
- >>> continue
- SyntaxError: 'continue' not properly in loop
- >>> a = [6.343, 333, 333, 1, 44 , 2 , 4 ,5, 66]
- >>> a
- [6.343, 333, 333, 1, 44, 2, 4, 5, 66]
- >>> a.count(333)
- 2
- >>> a.count()
- Traceback (most recent call last):
- File "<pyshell#5>", line 1, in <module>
- a.count()
- TypeError: count() takes exactly one argument (0 given)
- >>> a.append(
- 12)
- >>> a.insert(2, 100)
- >>> a
- [6.343, 333, 100, 333, 1, 44, 2, 4, 5, 66, 12]
- >>> a.index(333)
- 1
- >>> a.remove(333)
- >>> a
- [6.343, 100, 333, 1, 44, 2, 4, 5, 66, 12]
- >>> while a:
- x = a.pop()
- print(x, end=' ')
- 12 66 5 4 2 44 1 333 100 6.343
- >>> a
- []
- >>> a = [6.343, 333, 333, 1, 44 , 2 , 4 ,5, 66]
- >>> del a[1]
- >>> a
- [6.343, 333, 1, 44, 2, 4, 5, 66]
- >>> a.extend([1,2])
- >>> a
- [6.343, 333, 1, 44, 2, 4, 5, 66, 1, 2]
- >>> a.reverse()
- >>> a
- [2, 1, 66, 5, 4, 2, 44, 1, 333, 6.343]
- >>> a.sort()
- >>> a
- [1, 1, 2, 2, 4, 5, 6.343, 44, 66, 333]
- >>> b = ['dasda', 'dsds' , 'aaa', 'bf']
- >>> b.sort()
- >>> b
- ['aaa', 'bf', 'dasda', 'dsds']
- >>> c = [[1,2], [-3,4], [3,3]]
- >>> c.sort()
- >>> c
- [[-3, 4], [1, 2], [3, 3]]
- ----------------------------------------------
- a = []
- for i in range(10):
- a.append(i*i)
- print(a)
- ----------------------------------------------
- def squared(b):
- a = []
- for i in b:
- a.append(i*i)
- return a
- c = squared([1,4,8,10])
- print(c)
- ------------------------------------------------
- [1, 16, 64, 100]
- >>> a
- [1, 4, 8, 10]
- >>> c
- [1, 16, 64, 100]
- >>> [a**2 for a in range(5)]
- [0, 1, 4, 9, 16]
- >>> [a**2 for a in c]
- [1, 256, 4096, 10000]
- >>> from math import pi
- >>> round(pi, 2)
- 3.14
- >>> round(pi, 3)
- 3.142
- >>> [round(pi, i) for i in range(1,9)]
- [3.1, 3.14, 3.142, 3.1416, 3.14159, 3.141593, 3.1415927, 3.14159265]
- ------------------------------------------------------------------------
- a=[1,4,8,10]
- sq=[]
- for i in a:
- if i > 0:
- sq.append(i*i)
- print(sq)
- ------------------ lub ------------------
- [1, 16, 64, 100]
- >>> [x**2 for x in a if x > 0]
- [1, 16, 64, 100]
- ---------------------------------------------------------------------------
- wyrazy = ['pawel', 'pajor', 'bolek', 'gaborek']
- ini = [x[:2] for x in wyrazy]
- # bez y na drugim miejscu
- # ini = [x[:2] for x in wyrazy if x[1] != 'y']
- print(ini)
- -------------------------------------
- lista1 = [1,2,3]
- lista2 = [3,1,4,3]
- nowa = []
- for x in lista1:
- for y in lista2:
- if (x != y):
- nowa.append([x,y])
- print(nowa)
- pary2 = [[x,y] for x in lista1 for x in lista2 if x != y]
- print(pary2)
- ------------------------------------------------------------------
- v = [-4, -2, 0, 2, 4]
- # lista podwojonych wartosci obiektow z tej listy
- c = [2*i for i in v]
- # Tylko nieujemne wartosci z v
- x = [i for i in v if i > 0]
- # wartosci bezwzgledne
- z = [abs(i) for i in v]
- # lista [el, kwadrat el]
- b = [[i, i**2] for i in v]
- print(c)
- print(x)
- print(z)
- print(b)
- -------------------------------------------------------
- # chcemy spłaszczyć listę
- vec = [[1,2,3],
- [4,5,6],
- [7,8,9]]
- vec1 = []
- for i, x in enumerate(vec):
- for z, y in enumerate(x):
- vec1.append(vec[i][z])
- vec2 = [ y for x in vec for y in x ]
- print(vec1)
- print(vec2)
- ----------------------------------------------------------
- >>> 2 * [1,2,3]
- [1, 2, 3, 1, 2, 3]
- >>> 15 * [0]
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- ------------------------------------------------------------
- [15*[i] for i in range(10)]
- ------------------------------------------------------------
- [3*[5*[0]]]
- ------------------------------------------------------------
- a = 3 * [5 * [0]]
- [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
- >>> a[1][2] = 100
- >>> a
- [[0, 0, 100, 0, 0], [0, 0, 100, 0, 0], [0, 0, 100, 0, 0]]
- ------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement