Wednesday, April 8, 2015

Not Equal != - Python Tutorial

not equal !=



 


Not Equal !=


The not equal to symbol will compare the left side to the right side. If the object on the left is not equal to the object on right then Python will return True and if they are equal to each other then Python will return False


Not Equal != Examples


#Not Equal != Examples

>>> 5 != 4
True
>>> 5 != 5
False

If you have any questions about not equal != leave a comment below.



Tuesday, April 7, 2015

Equal To == - Python Tutorial

Equal To ==



 


Equal To ==


Equal to symbol == compares the object on the left to the object on the right if they are equal to one another than Python will return True and if the left is not equal to the right than Python will return False.


Equal To == Examples


#Equal To == Examples

>>> 5 == 5
True
>>> 5 == 6
False

If you have any questions about equal to == leave a comment below.


 



Monday, April 6, 2015

Greater Than > - Python Tutorial

>



 


The > simple is used as a comparison operator in Python.  If the object on the left of the > is greater than the object on the right then Python will return True.  If the object on the left of > is less than the object on right then Python will return False.


> Examples


 Examples" ># > Examples

>>> 2 > 1
True
>>> 1 > 2
False

If you have any questions about the Python > leave a comment below.



Python Comparison Operators - Python Numbers - Python Tutorial

Python Comparison OperatorsPython Comparison Operators


In the previous Python tutorial, we looked at booleans now we can use some Python comparison operators to get a boolean returned to us.  Python comparison operators are a vital part of programming with Python. We use the comparison operators to compare objects and tell the program to do something when a certain return happens.  We can compare if an object is greater than, less than, equal to, not equal to, greater than and equal to or less than and equal to.


Single Comparison Operators


== Equal Or Not Equal


The == symbols will check if the left side is equal to the right if so Python will return True if not then we get False. Do not make the mistake of using a single equal symbol like =, you will get an error or assign a variable.


#== Equal Or Not Equal

>>> 6 == 6
True
>>> 6 == 7
False

!= Not Equal or Equal


The != symbols will check if the left side is not equal to the right side if so Python will return True but if the left is equal to right then we will get False. This is opposite of the == operator.


#!= Not Equal or Equal

>>> 6 != 8
True
>>> 5 != 5
False

> Left is Greater Than Right


The > symbol will check if the left side is greater than the right.  If the left is greater Python will return True and if left is less Python will return False.


 Left is Greater Than Right" ># > Left is Greater Than Right

>>> 6 > 5
True
>>> 6 > 8
False

< Right is Greater Than Right 


The < symbol will check if the right side is greater than the left.  If the right if greater Python will return True and if the right is less Python will return false.


# < Right is Greater Than Right 

>>> 5 < 6
True
>>> 6 < 5
False

>= Left is Greater Than or Equal to Right


The >= symbols check if the left side is either greater or equal to the right side.  If the left is greater or equal to right then Python returns True if left side is less than right then Python returns False.


= Left is Greater Than or Equal to Right" ># >= Left is Greater Than or Equal to Right

>>> 7 >= 6
True
>>> 6 >= 6
True
>>> 5 >= 6
False

<= Right is Greater Than or Equal To Left


The <= right is greater than or equal to the left. If the right is greater or equal to the left then Python will return True if right side is less than Python will return False.


# <= Right is Greater or Equal To Left

>>> 6 <= 7
True
>>> 6 <= 6
True
>>> 6 <= 5
False

Chained Comparisons


Now that we have learned to use Comparison Operators in Python we can actually compare larger amounts of data using something called chained comparisons.  We will show you a bunch of examples below but they are pretty straight forward if you understand Comparision Operators so we will not explain each one.


#Chained Comparison Operators

>>> 4 < 6 < 8
True
>>> 7 > 4 == 4
True
>>> 9 != 7 != 6
True
>>> 10 > 8 > 6 > 4 > 2 > 0
True

>>> 5 > 2 and 7 < 10
True
>>> 6 == 6 or 7 != 5
True

Conclusion


Comparison operators are very simple to use and are effective in programming.  You will become very familiar to comparison operators as you move on in your Python programming career.  If you have any questions about Python comparison operators let us know via comment below.



Sunday, April 5, 2015

Booleans In Python - Python Numbers - Python Tutorial

booleans in pythonBooleans In Python


In this Python tutorial, we are going to look at booleans in Python. Booleans are sometimes called truth statements in programming. Booleans are returned only a True or False.  You may be asking why we are covering booleans in the numbers section our Python tutorial. Booleans are indeed part of the integer family. A True boolean is equal to 1 and a False boolean is equal to 0.


Boolean Examples in Python


We will be checking out examples of booleans. Some of the methods, operators or functions may have not been covered yet in our tutorial series.  Just follow along we are going to get to all these very shortly. All these examples will be performed in our Python interpreter.


#boolean Examples in Python

#Boolean Operations
>>> False or True
True
>>> True or False
True
>>> False or False
False
>>> True or True
True
>>> True and False
False
>>> True and True
True
>>> False and False
False
>>> not False
True

#Comparison Operators
>>> 7 < 9
True
>>> 8 > 8
False
>>> 8 != 9
True
>>> 8 == 8
True
>>> 8 <= 9
True


Proof That Booleans are Integers


#Proof That Booleans are Integers

>>> True + False
1
>>> True * False
0
>>> True ** 8
1
>>> type(True)
<class 'bool'>
>>> a = True + False
>>> type(a)
<class 'int'>

We will do a lot of work with Python booleans over the next couple of Python tutorials. If you have any questions about booleans in Python leave, a comment below so we can help you.


 



str() - Python Tutorial

str() built-in function



 


str() Built-in Function


str() is a built-in function in Python that will convert an other type like a integer, float, list, tuple and so on to a string.


Str() Syntax


syntax(argument)


The argument can be a integer, floating point number, list, tuple, dictionary, file, and so on.  The argument will be converted to a string.


str() Built-in Function Examples


#Str() Built-in Function

>>> str(6)
'6'
>>> str(7.6)
'7.6'
>>> str((6,75,9))
'(6, 75, 9)'
>>> str('cat': 'mary', 'dog': 'maggie')
"'cat': 'mary', 'dog': 'maggie'"

If you have any questions about the str() built-in function leave a comment below and we will do our best to assist you.


Saturday, April 4, 2015

float() - Python Tutorial

float() built-in function in python



 


Float() Built-in Function In Python


The float() built-in function converts integers and strings to floating point numbers.  This basic function simply just changes the type of object to a floating point number type in Python.


Float() Syntax


float(argument)


The argument can be a integer or string.  You can also include a float but it will do nothing to the floating point number. If you call the float() function on a integer the when be convert to float which it will contain a decimal and a zero.


Float() Examples


#float examples

>>> float(1)
1.0
>>> float("6")
6.0
>>> float("5.6")
5.6

If you have any questions about the float() built-in function leave a comment below and we will assist you.