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 :: python upload file to s3 
Python :: split strings around given separator/delimiter 
Python :: python create dictionary 
Python :: fix the size of a deque python 
Python :: Python NumPy tile Function Example 
Python :: django login required as admin 
Python :: python == vs is 
Python :: Encrypting a message in Python 
Python :: add vertical line in plot python 
Python :: tree in python 
Python :: continue statement in python 
Python :: nth catalan number 
Python :: why is c++ faster than python 
Python :: Function to plot as many bars as you wish 
Python :: how to check if digit in int python 
Python :: how to loop through an array in python 
Python :: field in django 
Python :: python list remove() 
Python :: _ in python 
Python :: python modulo 
Python :: getting current user in django 
Python :: for loop in python 
Python :: how to store categorical variables in separate dataframe 
Python :: frequency 
Python :: How to split a string into a dictionary in Python 
Python :: what is print in python 
Python :: create new spreadsheet 
Python :: matplotlib units of scatter size 
Python :: python unicode point to utf8 string 
Python :: python logical operators code 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =