“Kurs umieszczenia GFG” Kod odpowiedzi

Kurs umieszczenia GFG

a=[2,2,4,1]
b=a
a.sort()
// a now points to object [1,2,2,4]
c=sorted(b)
//c and b also points to [1,2,2,4] 
// sort works on array only but sorted also on strings but return array of char
s="sjndk"
print(sorted(s))
// prints ['d', 'j', 'k', 'n', 's']
// sorted also works on list of strings(sorts alphabetically)
ap_Cooperative_dev

Kurs umieszczenia GFG

w=["as","3e","1"]
a='vf'.join(w)
print(a)
//displays string asvf3evf1
ap_Cooperative_dev

Kurs umieszczenia GFG

//strings are immutable in python but arrays are mutable
s="sksks"
s[0]="x"
// compilation error as can't assign
ap_Cooperative_dev

Kurs umieszczenia GFG

w=["ab","e","e3"]
res = reversed(w)
// res is array w reversed ["e3","e","ab"]
ap_Cooperative_dev

Kurs umieszczenia GFG

  s="ab.e.e3"
  w = s.split('.')
  // w is ["ab","e","e3"]
ap_Cooperative_dev

Kurs umieszczenia GFG

class A:
    def a(self,st):
        return 1
            
    def b(self,s1,s2) :
        d= self.a(7)
        return d    
obj=A()
print(obj.b(1,2))
//prints 1
// so basically every function in a class have self which is object
// like in each of them self is there -- def a(self,st): & def b(self,s1,s2):
// used to other functions of that class and 
//it's used to call other functions & while calling that other function
// we don't write self inside it
// d= self.a(7)
ap_Cooperative_dev

Kurs umieszczenia GFG

When applied to numbers, lexicographic order is increasing numerical order, i.e. 
increasing numerical order (numbers read left to right).
For example, the permutations of {1,2,3} 
in lexicographic order are 123, 132, 213, 231, 312, and 321. 
When applied to subsets, two subsets are ordered by their smallest elements.
ap_Cooperative_dev

Kurs umieszczenia GFG

The [0] * x creates a list with x elements. So,
>>> [ 0 ] * 5
   gives [0,0,0,0,0]

******** warn:they all point to the same object.
This is cool for immutables like integers but a pain for things like lists.
>>> t = [[]] * 5
>>> t
[[], [], [], [], []]
>>> t[0].append(5)
>>> t
[[5], [5], [5], [5], [5]]
>>> 
ap_Cooperative_dev

Kurs umieszczenia GFG

>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
ap_Cooperative_dev

Odpowiedzi podobne do “Kurs umieszczenia GFG”

Pytania podobne do “Kurs umieszczenia GFG”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu