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

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 :: np array size 
Python :: python types of loops 
Python :: django not migrating 
Python :: accessing a variable from outside the function in python 
Python :: pypdf2 advanced tutorial 
Python :: Python Generators with a Loop 
Python :: random seed python 
Python :: insert-cells-in-empty-pandas-dataframe 
Python :: python datetime to unix timestamp 
Python :: Model In View Django 
Python :: Convert Int to String Using format() method 
Python :: python find dir 
Python :: python create unreadable save file 
Python :: np.random.choice 
Python :: python if file exists append else create 
Python :: how to add array and array in python 
Python :: s.cookie.set python 
Python :: ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_3_1:0", shape=(None, None, 71), dtype=float32) at layer "input_3". The following previous layers were accessed without issue: [] 
Python :: convert pandas data frame to latex file 
Python :: optional parameter in python 
Python :: multiple line comments 
Python :: FileSystemStorage django 
Python :: extracting values in pandas 
Python :: seaborn stripplot min max 
Python :: librosa python 
Python :: spliting the text to lines and keep the deliminaters python 
Python :: create pdf in python 
Python :: xargs in python 
Python :: numpy array [-1] 
Python :: how to get parent model object based on child model filter in django 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =