Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

gfg placement course

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

gfg placement course

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

gfg placement course

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)
Comment

gfg placement course

  s="ab.1e.1e3"
  w = s.split('.1')
  // w is ["ab","e","e3"]
  // use help(str.split) in your python IDE to know split in detail.
Comment

gfg placement course

w=["as","3e","1"]
a='vf'.join(w)
// w neccessarily needs to be a list of strings.
print(a)
//displays string asvf3evf1
Comment

gfg placement course

// for 2 strings s1 and s2 to be anagrams
// both conditions should be True
// 1 their length is same or 
len(s1)==len(s2)
// 2 rearranging chars alphabetically make them equal or 
sorted(s1)==sorted(s2)
Comment

gfg placement course

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

gfg placement course

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)
Comment

gfg placement course

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.
Comment

gfg placement course

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]]
>>> 
Comment

gfg placement course

sum(a)
a is the list , it adds up all the numbers in the 
list a and takes start to be 0, so returning 
only the sum of the numbers in the list.
sum(a, start)
this returns the sum of the list + start 
// Python code to demonstrate the working of 
// sum()
   
numbers = [1,2,3,4,5,1,4,5]
  
// start parameter is not provided
Sum = sum(numbers)
print(Sum)
  
// start = 10
Sum = sum(numbers, 10)
print(Sum)
Comment

PREVIOUS NEXT
Code Example
Python :: sum of the number in a list in python 
Python :: anaconda install python 
Python :: python tuple methods 
Python :: prime numbers 1 to 100 
Python :: python round function example 
Python :: join tables pandas 
Python :: math floor python 
Python :: cross entropy 
Python :: typing racer 
Python :: python ternary operators 
Python :: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 
Python :: python how to find the highest even in a list 
Python :: rabbitmq python 
Python :: array and list in python 
Python :: combination in python math 
Python :: python wait 
Python :: how to save python variables locally 
Python :: python vrer un fichier texte 
Python :: how to update image in django 
Python :: best python programs 
Python :: How to assign value to variable in Python 
Python :: how to append data in excel using python pandas 
Python :: how to flatten list of lists in python 
Python :: # Import KNeighborsClassifier from sklearn.neighbors 
Python :: receipt ocr python 
Python :: addition array numpy 
Python :: qtablewidget add row python 
Python :: class views django slug 
Python :: how long is the pyautogui script 
Python :: how to make take command in python 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =