Hi friends.
This is the 4th lesson of Python tutorial. In this lesson we'll talk about booleans and some built-in functions in Python.
The naming of Boolean is inspired by the British George Bool's name .
Booleans are objects can hold only truth values, truth values are either True or False .
True and False must be capitalized in programming.
Operations on booleans:
There are three operations could be applied on booleans, which are and,or and xor.
And,or and xor are called "logical operators".
And-operator
The operator and returns True as result if the two operands (objects) were true , otherwise, returns False
Examples :
True and True result is True
True and False result is False
Or-operator
returns True as result if one of the two operands (objects) were true.
Examples :
True or False result is True
False or False result is False
Xor-operator
returns True if the two operands (objects) weren't same.
Examples :
True xor False result is True.
True xor True result is False.
Note:
You can use "&&","||" and "^"respectively instead of " and","or" and "xor".
Now, let's turn to new built-in functions in Python, type, id, int, float and complex.
Type (obj): takes any object as parameter and returns its type.
Id (obj) : takes any object as parameter and returns an integer that integer stands for the memory address for the object.
Int (str) : takes any numerical string as parameter and converts it to an integer.
Float (str) : takes any digital string as parameter and concerts it to a floating point number.
Complex (real=0, imagery=0) : takes two integers or floating point numbers as parameters and makes a complex number from them.
Thanks for reading.
This is the 4th lesson of Python tutorial. In this lesson we'll talk about booleans and some built-in functions in Python.
Booleans are objects can hold only truth values, truth values are either True or False .
True and False must be capitalized in programming.
Operations on booleans:
There are three operations could be applied on booleans, which are and,or and xor.
And,or and xor are called "logical operators".
And-operator
The operator and returns True as result if the two operands (objects) were true , otherwise, returns False
Examples :
True and True result is True
True and False result is False
Or-operator
returns True as result if one of the two operands (objects) were true.
Examples :
True or False result is True
False or False result is False
Xor-operator
returns True if the two operands (objects) weren't same.
Examples :
True xor False result is True.
True xor True result is False.
Note:
You can use "&&","||" and "^"respectively instead of " and","or" and "xor".
Now, let's turn to new built-in functions in Python, type, id, int, float and complex.
Type (obj): takes any object as parameter and returns its type.
Id (obj) : takes any object as parameter and returns an integer that integer stands for the memory address for the object.
Int (str) : takes any numerical string as parameter and converts it to an integer.
Float (str) : takes any digital string as parameter and concerts it to a floating point number.
Complex (real=0, imagery=0) : takes two integers or floating point numbers as parameters and makes a complex number from them.
Thanks for reading.
No comments:
Post a Comment