xxxxxxxxxx
"""
'//' is floor division on python which mean
the result will be rounded down (eg: 3.14 become 3), so
'5 // 2' will be 2
"""
xxxxxxxxxx
>>> fruits = ['lemon', 'pear', 'watermelon', 'tomato']
>>> print(fruits[0], fruits[1], fruits[2], fruits[3])
lemon pear watermelon tomato
>>> print(*fruits)
lemon pear watermelon tomato
xxxxxxxxxx
#In Python, the double forward slash (//) is the floor division operator.
#It is used to perform integer division, returning the largest integer that is less
#than or equal to the result of the division.
x = 10 // 3
print(x) # Output: 3
xxxxxxxxxx
""" 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)
xxxxxxxxxx
# @ 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)
xxxxxxxxxx
import subprocess
command = "ls -l" # Replace with desired shell command
subprocess.call(command, shell=True)
xxxxxxxxxx
# Ternary operator using question mark
condition = True
result = "Condition is True" if condition else "Condition is False"
print(result)