A module in Python is a Python source file that contains definitions and use them in a script or in an interactive instance of the interpreter.
We use modules to divide a piece of software into separate but cooperating parts.
Continue reading “Python Basics: Module & Namespace”
Tag: Python
To Compare Float, Double, or Long Data Types
A way to make doubles, floats, or longs ‘equal’.
Float a=1.56148; Float b=1.56139;
Float threshold = 0.00009 or 0.0001 //difference of Float a and Float b
if (Math.abs(a-b) <= threshold){//Or < threshold
//logic here
}
Continue reading “To Compare Float, Double, or Long Data Types”
Python Basics: Immutable Sequence Type & Tuples 2
To get an element of a tuple in order to read them over, you can use the same way while you are using a list:
tuple=(1, 10, 100, 1000)
print(tuple[0]) -> the index is 0, so output is 1
print(tuple[-1]) -> the last index, so the output is 1000
print(tuple[1:]) -> starting index is 1, so the output is (10,100,1000) Continue reading "Python Basics: Immutable Sequence Type & Tuples 2"
Python Basics: Immutable Sequence Type & Tuples 1
Sequence type: a data type in Python which is able to store more than one value or less than one value (as a sequence my be empty), and these values can be sequentially browsed element by element (like a list).
Mutability: a property of any of Python’s data that describes its readiness to be freely changed during program execution.
Continue reading “Python Basics: Immutable Sequence Type & Tuples 1”
Python Basics: Define A Function
It is easy…and it’s similar to if or for statement formats:
def functionName():
//logics here...
Python Basics: List
A list in Python is like an array or a list in Java.
Still, it’s very simple to declare a Python list:
list = [1,2,3,4] <- an int type list
list = ["2","Hello","World"] <- a string type list
list = [] <- just to define an empty list
Python Basics: Variables & Data Types
The second simple part of Python is its variables.
As mentioned in previous Python post, it only needs you to think of an appropriate name, and a value to define (assign) it.
Though, you still need to keep an eye on the data types.
var1 = 2
var2 = '2'
var3 = var1 + va2
print(var3)