Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

* 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 :: open python file with read write permissions 
Python :: how to do formatting in python with format function 
Python :: label with list comprehension python 
Python :: get dummies pandas 
Python :: print index in for loop python 
Python :: fit function tensorflow 
Python :: selenium options python path 
Python :: Converting categorical variable to numeric variable in python 
Python :: pandas groupby 
Python :: create an array filled with 0 
Python :: theme_use() tkinter theme usage 
Python :: mistborn series 
Python :: print value of array python 
Python :: How to calculate accuracy with two lists in python 
Python :: python generator function 
Python :: warnings.warn("DateTimeField %s received a naive datetime (%s)" 
Python :: how to split strings in python 
Python :: request.args.get check if defined 
Python :: boder color in tkinter 
Python :: Example pandas.read_hfd5() 
Python :: dynamic printing 
Python :: run python test in terminal 
Python :: image data generator tensorflow 
Python :: tic tac toe pygame 
Python :: py search and get objects from array 
Python :: Get text without inner tags text in selenium 
Python :: python melt 
Python :: string remove suffix python 
Python :: SciPy Spatial Data 
Python :: conda create new env 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =