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

* 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 :: pandas mean of n columns 
Python :: run a for loop in python 
Python :: what is modulus in python 
Python :: Uninstalling/removing a package is very easy with pip: 
Python :: django upload multiple files 
Python :: Merge two Querysets in Python Django while preserving Queryset methods 
Python :: np array size 
Python :: string + string in python 
Python :: pandas get higher value of column 
Python :: jupyter notebook bold text 
Python :: how to concatenate two strings in python 
Python :: plt.scatter background color 
Python :: prolog finding the max from a list of facts 
Python :: python concatenate dictionaries 
Python :: python create unreadable save file 
Python :: Split a list based on a condition 
Python :: python secret 
Python :: python variables 
Python :: value list in django 
Python :: # /usr/bin/env python windows 
Python :: sqlalchemy integrityerror 
Python :: sorted function in python 3 
Python :: .replace python 
Python :: python module has no attribute 
Python :: pandas order dataframe by column of other dataframe 
Python :: python console 
Python :: blender change text during animation 
Python :: checking length of sets in python 
Python :: hmac sha256 python 
Python :: how to generate python code 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =