Sunday, April 19, 2015

Python List Basics - Python Basics - Python Tutorial

Python listPython List


In this Python tutorial, we are about to take a brief tour of another data type in Python called a list. A Python list is a positionally ordered collection of data. A List has no maximum size limitations so your list can be as large as you want or need it can even be empty which is referred to an empty string. We are able to modify the list after they are created by assignment or specific list methods. A Python list is very useful when programming we could use them for so many reasons like a sports roster, list of business and many more.


Python List Syntax


A list is declared by a square bracket( [ ] ) and the content inside a list referred to as the list data and each piece of data is separated by a comma.


List Syntax


[987, “Python”, “Dog”, 1, -5, “Cat”]

In the example above we have created a list that contains numbers and strings. Each piece contained in the list is separated by a comma.


Python List Sequence


Like strings a list is in a sequence but unlike strings the index on counts pieces of data(between the commas) in the list. We will use the above example in list syntax to see how the sequence work in list.
















List987“Python”“Dog”1-5“Cat”
Index012345

 


Python List Examples


Fire up your Python interpreter and follow long.  We will create some Python list and assign them to a variable. This will be a good chance for you to practice creating and assigning list.


#Create a Python list
>>> a = ["Tom", "Mike", "Jaime", "Jake"]

#Call the Python List
>>> a
['Tom', 'Mike', 'Jaime', 'Jake']

#Create a Python List
>>> b = [987, 897, 34, 21, 67]

#Call the Python List
>>> b
[987, 897, 34, 21, 67]

#Try slicing the list we have not tried this before
>>> b[2]
34
>>> b[-1]
67
>>> b[-0]
987
>>> b[-2]
21

#Create a list
>>> list = ["eggs", "milk", "apples", "tea"]

#call the list
>>> list
['eggs', 'milk', 'apples', 'tea']

Now we have complete our brief overview of Python list we can now set up and call list. We will cover list in full in a couple chapters.  If you have any questions leave us a comment below or Q & A section.



Saturday, April 18, 2015

Python String Basics - Python Basics - Python Tutorial

Python StringPython String


In today’s Python tutorial, we are going to look at another important data type that we use often in Python. We are about to focus on a data type called a string. A string is a sequence of data like text or a collection of bytes. In this tutorial, we are going to only be focusing on an introduction to the Python string. We will dig deeper into strings in chapter 4 of this series.


What is a String?


A string contains a list of characters in a specific order(sequence). The characters in a string can be letters, numbers, special characters like symbols and spaces.  Strings have no limit on how long they may be and you may also take a string that contains no characters this is called a “empty string”.


What is the Python String Syntax?


The syntax of a string in Python is quite simple. We create a string by enclosing characters in quotes which can be single quotes, double quotes or triple quotes.  Which method you use is entirely up to you. Through out the tutorials I will be using single quotes for most of the tutorials except when certain situations arise where single quotes are not the best option.


Python String Syntax


‘This is a string in Python’


“This is a string in Python”


”’This is a string in Python”’


“””This is a string in Python”””


We can not start with single quote and end with a double quote.  We must start and end with same type of quote.


String Syntax Examples


We will be using a print statement in these examples we have not discussed the print statement.  The print statement tells Python to print the content contained in the print statement to the screen.  The syntax for the print statement is print().


#String Syntax Examples

>>> print('This is a string')
This is a string

>>> print("This is a string")
This is a string

>>> print('''This is a string''')
This is a string

>>> print("""This is a string""")
This is a string

 


Why Is A String a Sequence?


We mentioned earlier that a string is a sequence of data.  The data in a string takes on a positional ordering which means each character in a string has an exact position.  We can access the exact position of a character in a string by its index which is a numbered position of each character.  Each string index starts with the number 0 and counts up from that point(left to right).  Look at the example below.


 































This
is
a
String
0123456789101112131415

 


In the above example you can see that each letter and space have specific index position starting a 0. It is safe to say each character is its on data which is packaged together to create a string.  We will dive into this some more in chapter 4.


Strings are Immutable


Strings can not be changed once they have been created.  This is why they are considered immutable.  We can change a string by creating a new string but the current string can not be changed.


Python String Basics Conclusion


In this Python tutorial we took a very brief look at the Python string.  We didn’t even scratch the surface when it comes to strings but we can now create a string and we understand that each character in a string is in a specific order because strings are just a collection of letters, numbers, spaces and special characters.  We also learned that strings are immutable meaning once we create them we can not change them unless we create a new string.



Floating Point Number - Python Tutorial


A floating point number is a number that contains a decimal point. These numbers are floating point numbers 4.5, 767.43, -89.342343, -67.8988893



Friday, April 17, 2015

Integer - Python Tutorial


A integer is a number that doesn’t have a decimal point.  These numbers are integers 1, 4, 6, -4, -6, -99



Python Numbers Basics - Python Basics - Python Tutorial

Python NumbersPython Numbers


In this Python tutorial we be covering numbers in the Python Programming Language. If you have done any programming in the past, numbers in Python may look very familiar to you.  Numbers in programming languages really do not change much but they are one of the most important data types in programming, and this holds true in Python as well.

We use numbers in almost every program. We write with Python understanding the difference between integers and floating-point numbers is important. We are required to know how to use mathematical equations with our numbers so in this tutorial on numbers we are going to focus on number types and the math we can apply to each number type.


Integers


An integer is a number that has no decimal point associated with it.  These are integers 34, 5, 89, -45, -23 and so on. A number is considered an integer as long as it does not contain a decimal point.


Booleans


Integers have a subfamily called Booleans as well. Booleans return either True or False which may be confusing because they do not look like an integer. The reason why they are a part of the integer family is because True is actually equal to the integer value 1 and False is equal to the integer value 0.


Floating Point Numbers


Floating point numbers are numbers with a decimal point connected with them. Floating point numbers have more precision than an integer which makes floating point numbers more desirable when you are looking for precision in your programs. These are floating point numbers 5.5, 7.53423, 45323.1, -4523.9, -0.2 and so on.


Complex Numbers


Complex numbers are another number type in the Python Programming Language.  We will not cover complex numbers in this tutorial.  We will save them for a later chapter in our Python tutorial series.


Math With Python


What good are Python numbers without math? In the rest of our tutorial, we will look at how to perform math in Python. You will be required to open your Python interpreter in your terminal or command prompt.To start the interpreter follow the steps for your operating system. Mac users: Once you open the terminal type python3 and press enter. Windows users: Once in your command prompt type python.


Addition


Addition gives the ability to add numbers together. We use the plus(+) sign to indicate we want to add in Python. Let’s take a look at some examples of addition.


#integers
>>> 2 + 2
4
>>> 6 + -4
2
>>> -3 + 69
66
>>> 5673 + 43234
48907

#floats
>>> 5.6 + 3.4
9.0
>>> 67.56423 + 89.34
156.90422999999998
>>> -23.3 + 4.5
-18.8

#floats + integers
>>> 5.6 + 5
10.6
>>> 9 + -4.2
4.8
>>> 7.0 + 5
12.0

Addition in Python is pretty straight forward.  Addition works just like it did in first grade. Note if you add a integer and and a floating point number together then you will get a float.


Subtraction


Subtraction in Python gives us the ability to subtract numbers.  We use the hyphen(-) symbol to indicate subtraction in Python. Lets take a look at some subtraction examples in Python.


#integers
>>> 5 - 7
-2
>>> 6 - 4
2
>>> 6789 - 2345
4444

#floats
>>> 5.7 - 8.9
-3.2
>>> 4.5 - 2.0
2.5
>>> 65739 - 9834
55905

#floats - integer
>>> 4 - 4.5
-0.5
>>> 56 - 33.33
22.67
>>> 4.0 - 5
-1.0

Multiplication


Multiplication gives us the ability to multiply numbers in Python.  We use the star(*) symbol to indicate we want to multiply numbers together.  Let’s take a look at some examples of multiplication in Python.


#integers
>>> 5 * 6
30
>>> 76 * 4353
330828
>>> 235 * -9878
-2321330

#floats
>>> 56.43 * 989.02
55810.3986
>>> 45.1 * -43.1
-1943.8100000000002

#floats * integers
>>> 56 * 43.6
2441.6
>>> 434 * 9834.32
4268094.88

Division


Division in Python gives us the ability to divide numbers in Python.  We use the backslash(/) symbol to indicate that we want to divide numbers. Let’s take a look a few examples of division in Python.


#integers
>>> 56 / 45
1.2444444444444445
>>> 89 / 43
2.0697674418604652
>>> 9 / -3
-3.0
>>> 9 / 3
3.0

#floats
>>> 76.4 / 9.0
8.488888888888889
>>> 653.55 / 54
12.102777777777776
>>> 5.6 / 2.3
2.4347826086956523

When we divide integers Python will return a float. We will look at how to change a float to integer in our numbers chapter.

Now that we covered the four basic mathematical operators in Python we can safely move on for now.  We will have a chapter that will dive very deep into the numbers and the other mathematical operators in Python but for now we have covered the important ones.

This tutorial has covered the very basic Python numbers and Python mathematical operators. Do not forget to check out our chapter on numbers for more in depth information on Python numbers. If you have any questions please leave a comment below.



Thursday, April 16, 2015

Assign a Variable in Python - Python Basics - Python Tutorial

Assign a Variable in PythonAssign a Variable in Python


Before we can focus on Python basics we need to learn how to assign a variable in Python.  We will dive deeper into variables in a later tutorial.  This tutorial main focus is on assigning variables and calling variables after they been assigned which will make learning data types in this chapter easier.


Variable Creation


A variable in Python is created when it is assigned a value.  We assign a value to a variable with the equal sign(=).  Unlike other languages we do not need to assign a type or even declare it before a value is assigned to the variable.


Variable Syntax


Variable name must start with a letter and after first letter it contain numbers.  Variables can not start with numbers.


var = 3


var2 = “Cat”


Var3 = [123, 567, 987, 3456]

The above are examples how we create a variable by assigning it a value.


Call a Variable


To call a variable in python we simply just type the variable name and press return.  Check out the examples below for a better understanding.


Creating and Calling Variables in Python Examples


>>> a = 7
>>> a
7
>>> var = "This is our var"
>>> var
'This is our var'

This is a very simply overview of assign a variable in Python.  We will dig deeper into variables in a later tutorial.



Python Basics - Chapter 2 - Python Tutorial

Python BasicsIn the previous chapter we just gave you an overview of the Python Programming Language and we really did not get a chance to see of the language works. In chapter 2 of Learning Python, we are going to focus on Python Basics and actually get to practice typing some code. We will explore all of Python’s core data types with just an introduction to each of them. Our main focus in this chapter is cover why and how we would need a certain data type. Later in the tutorials we will really dive deep into each data type offering you even more knowledge.


Data Types To Be Covered


Numbers – 7534, 87432.33


Strings – ‘Hello World!’


List – [ 1, 89, 45, 5]

Dictionaries – ‘dog': ‘Maggie’, ‘cat': ‘Missy’


Tuples – (‘Tom’, ‘John’)


and more


Python Basics Tutorials List


  1. Assign a Variable in Python

  2. Python Numbers

  3. Python Strings

  4. Python List

  5. Python Dictionaries

  6. Python Tuples

  7. How To Install Sublime Text on Mac OS X

  8. How To Install Sublime Text on Windows