Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

what is // in python

"""
  '//' is floor division on python which mean
  the result will be rounded down (eg: 3.14 become 3), so
  
  '5 // 2' will be 2
"""
Comment

* in python

>>> fruits = ['lemon', 'pear', 'watermelon', 'tomato']
>>> print(fruits[0], fruits[1], fruits[2], fruits[3])
lemon pear watermelon tomato
>>> print(*fruits)
lemon pear watermelon tomato
Comment

** in python

#** is the exponent symbol in Python, so:
print(2 ** 3)
#output: 8
Comment

// in python

print(3 // 2)
# 1
print(3 / 2)
# 1.5
Comment

** in python

""" depends on the data type too """
def callme(key1, key2):
  print(key1, key2)
    
obj1 ,obj2 = 6, 9
obj3 = {
  "key1": 1,
  "key2": 2
}
callme(**obj3) # easy for calling functions
print(obj1 ** obj2) # Here it is a operator (for calculating obj1 ^ obj2)
Comment

@ in python

# @ is used for matris multiplication
class Mat(list):
    def __matmul__(self, B):
        A = self
        return Mat([[sum(A[i][k]*B[k][j] for k in range(len(B)))
                    for j in range(len(B[0])) ] for i in range(len(A))])

A = Mat([[1,3],[7,5]])
B = Mat([[6,8],[4,2]])

print(A @ B)
Comment

** in python

print(10 * 10)
# 100
print(10 ** 10)
# 10000000000
Comment

** in python


>>> class Adder(object):
        def __init__(self, num=0):
            self.num = num

        def __iadd__(self, other):
            print 'in __iadd__', other
            self.num = self.num + other
            return self.num

>>> a = Adder(2)
>>> a += 3
in __iadd__ 3
>>> a
5

Comment

PREVIOUS NEXT
Code Example
Python :: django timezone india 
Python :: python utf8 
Python :: print python 
Python :: pandas replace column name from a dictionary 
Python :: reverse string in python 
Python :: how to print variables in a string python 
Python :: calculate integral python 
Python :: how to write a numpy array to a file in python 
Python :: pillow read from ndarray 
Python :: keep only duplicates pandas multiple columns 
Python :: how to make a kivy label multiline text 
Python :: what is my python working directory 
Python :: nan float python 
Python :: python list of all tkinter events 
Python :: How to Add R to Jupyter Notebook 
Python :: pandas groupby size column name 
Python :: pandas summarize all columns 
Python :: django static media 
Python :: pip install python 
Python :: how to import .csv file in python 
Python :: confusion matrix python code 
Python :: fuzzy lookup in python 
Python :: TinyDB 
Python :: python tempfile 
Python :: plt.suptitle position 
Python :: how to add value to to interger in python 
Python :: python file location path 
Python :: how to print on python 
Python :: remove all rows without a value pandas 
Python :: plt.xticks 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =