“curso de colocación de GFG” Código de respuesta

curso de colocación de 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

curso de colocación de GFG

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

curso de colocación de GFG

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

curso de colocación de GFG

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

curso de colocación de GFG

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

curso de colocación de 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

curso de colocación de 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

curso de colocación de 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

curso de colocación de GFG

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

Respuestas similares a “curso de colocación de GFG”

Preguntas similares a “curso de colocación de GFG”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código