Sunday, April 26, 2015

Complete Guide to Variables - Python Variables - Python Tutorial

Python VariablesComplete Guide to Variables


In an earlier Python tutorial, we introduced how to assign a variable in Python but as you know we like to go very deep into Python here at Learn Python Tutorial and we are going to very deep into Python variables.What is really cool about Python is creating a variable is so simple it confuses some programmers coming from other languages.


Python Variables Are So Simple


Let’s start by making a simple variable that contains an integer – var = 2. Here is why Python variables are so damn easy! First we do not have to tell Python that var is a variable like other languages and we do not need to tell Python that var is going to contain an integer. If you have been working on other programming languages you may be thinking what, how and why? This is because Python determines variables and types at runtime so there is no need to declare this information before time.


Creating Variables


We already looked at creating variables in a previous tutorial but a review will be a good thing. To create a variable we give the variable a name like “var” and assign the variable by using the equal symbol(=) with a value like an integer of 6. When making a variable it must always have a value to exist if the variable is not assigned a value then that variable would not exist. If we assign the variable again to a different value, then that variable would take on the new value and drop the old value.   In Short… Initial assignment creates the variable in Python and changing a value in a variable is referred to as reassignment.


How About Type Information In Variables?


Variables never ever store any information! What?  Variables are just a label or a title that points to an object(value) at a certain point of time. The object includes the value, type information and reference counter. Check out the diagram below this will hopefully explain it better.


Python Variables


 


*Note – The Pointer in Python is referred to as a Reference


How Are Variables Used?


When the script is ran the variables are replaced by their associated objects stored values. This is the main reason why all variables must be assigned before the script is ran and if they are not assigned we will get errors.


Variables Life Cycle


What happens from the time a variable is created to the time object is no longer used? First we will create a variable and then we will talk about the life cycle.


var = 9


Above we create a variable and it references an object that contains the value of 9. We will take a closer look at what happens here.


The Life Cycle


  1. An object is created that holds the value of 9 (allotted part of memory that stores the value 9, integer type and the reference counter.

  2. A variable is created but it really does not exist till it is assigned to an object(look at step 3)

  3. The pointer(reference) is created which associates the variable of the object.

  4. When a variable no longer exists then, Python may remove the object to free up space. This does not always happen because some objects may be used more than once, but Python makes that decision when objects will be used more than once.

Important Information About Python Variables


  • Variables can not point to other variables but we can write something like this var1 = var but they both reference the same object not each other.

  • Objects can reference other objects like in list, dictionaries and tuples can reference other objects since the store different types of values within those data types.

  • Python runs its own cache which removes objects that are no longer needed to free up memory which will help programs run faster.

 


We have dug deep into Python variables and we gave you a lot of information and some may go over your head but it is import to know the following.


  • Variables do not store information but reference the location where the information is stored.

  • Objects are just a block of memory which contains the value, type information and reference counter.

  • Variables are replaced by the value when program is ran

  • Variables are not created till they are assigned a value and they must have a value to exist.

If you have any questions about our tutorial on Python Variables leave a comment below.



Saturday, April 25, 2015

Python Variables - Chapter 3 - Python Tutorial

Python VariablesPython Variables


In this chapter, we are going to explore everything you need to know about Python Variables. This chapter on Python Variables will begin our comprehensive Python education tutorials.  We will go at a snail’s pace but we will cover everything you need to know about the Python Programming Language. As we dig into variables, in Python we will see how Python is different from other programming languages you may know.This chapter will also give to light how flexible the Python language is. Check out the Python variables Tutorial list below.


Python Variables Tutorial List


  1. Complete Guide To Python Variables

  2. Why Is There No Type Declaration In Python

  3. How Python Variables Reference Objects

  4. Python Keywords

  5. Python Garbage Collection

sequence - Python Tutorial

sequenceSequence – In Python a sequence is a way to store data in an organized and efficient way.  There are several different data types in Python that use a sequence and they are strings, list and tuples are the most used sequences in Python and there are some rarer ones like ranges and binary sequences.



Friday, April 24, 2015

rmdir - Python Tutorial

rmdir – Allows us to remove directories via the terminal. This command makes for an easier and quicker way to remove folders. If your directory contains files or folders the rmdir will not work. The Work around to delete a directory that contains folders or files we need to use rm -rf folder name to delete that directory. Be Careful you do not delete an important directory or files there is no returning from this.


rmdir Example


#Find a file to delete
Thomass-MBP:desktop Tommy$ ls
Screen Shot 2015-03-02 at 9.17.06 AM.png
Screen Shot 2015-03-02 at 9.20.35 AM.png
Screen Shot 2015-03-02 at 9.28.59 AM.png
Screen Shot 2015-03-02 at 9.35.50 AM.png
django
learnPython
manage.py
movies
projects
python
test
videos
web developement notes
wizardtut.py

#We will remove Test
Thomass-MBP:desktop Tommy$ rmdir test
Thomass-MBP:desktop Tommy$ ls
Screen Shot 2015-03-02 at 9.17.06 AM.png
Screen Shot 2015-03-02 at 9.20.35 AM.png
Screen Shot 2015-03-02 at 9.28.59 AM.png
Screen Shot 2015-03-02 at 9.35.50 AM.png
django
learnPython
manage.py
movies
projects
python
videos
web developement notes
wizardtut.py

#Remove a directory that contains folders and files
Thomass-MBP:desktop Tommy$ mkdir test
Thomass-MBP:desktop Tommy$ cd test
Thomass-MBP:test Tommy$ touch test.py
Thomass-MBP:test Tommy$ ls
test.py
Thomass-MBP:test Tommy$ cd ..
Thomass-MBP:desktop Tommy$ ls
Screen Shot 2015-03-02 at 9.17.06 AM.png
Screen Shot 2015-03-02 at 9.20.35 AM.png
Screen Shot 2015-03-02 at 9.28.59 AM.png
Screen Shot 2015-03-02 at 9.35.50 AM.png
django
learnPython
manage.py
movies
projects
python
test
videos
web developement notes
wizardtut.py
Thomass-MBP:desktop Tommy$ rm -rf test
Thomass-MBP:desktop Tommy$ ls
Screen Shot 2015-03-02 at 9.17.06 AM.png
Screen Shot 2015-03-02 at 9.20.35 AM.png
Screen Shot 2015-03-02 at 9.28.59 AM.png
Screen Shot 2015-03-02 at 9.35.50 AM.png
django
learnPython
manage.py
movies
projects
python
videos
web developement notes
wizardtut.py
Thomass-MBP:desktop Tommy$

 



How to Install Sublime Text on Windows - Python Basics - Python Tutorial

How to Install Sublime Text on WindowsHow to Install Sublime Text on Windows?


In this Python tutorial, we will take a very quick look at how to install Sublime Text on Windows. Sublime Text is a text editor which will enable us to edit our Python code as we move on with our Python Tutorials. I am sorry this tutorial does not contain screenshots, but my wife’s laptop doesn’t take screenshots for some odd reason.

Step 1 – Visit Sublime Text website at http://sublimetext.com

Step 2 – Located and press the download menu item on the top bar of their website.

Step 3 – About half way down the page you will see two links one for Windows and another for Windows 64 bit pick which operating system you are using.


Step 4 – Your download of Sublime Text will begin.

Step 5 – Locate your download and run the sublimetext.exe to start the installation of the editor

Step 6 – Open File – Security Warning will pop up we simply just press run.

Step 7 – Welcome To Sublime Text – Press Next

Step 8 – Select Destination Folder – Press Next keep in your main folder

Step 9 – Select Additional Task – Press Next

Step 10 – Ready to Install – Press Install

Step 11 – Open Sublime Text to make sure the installation worked

Now that we have successfully learn how to install Sublime Text on Windows we can turn to writing some Python Code. If you have any questions leave a comment below.


 



Thursday, April 23, 2015

How to Install Sublime Text on Mac OS X - Python Basics - Python Tutorial

How to Install Sublime Text on Mac OS X How to Install Sublime Text on Mac OS X?


We are moving right along with our Python tutorials and we are about to go very deep into the Python language but before we dig any deeper we need a program which is called a text editor to edit our code.  I have my favorite and you may have your own favorite if you have a text editor that you are comfortable with then use that one.  If you do not have have a text editor yet I will show you how to install Sublime Text on your mac in todays tutorial. I have been using Sublime Text for years and I believe that it is one of the best text editors and its completely free. They do ask you to upgrade to a paid version and you may do that if you want but it is not necessary. Make sure you follow each step of how to install Sublime Text on Mac OS X closely so you install the editor correctly.


How to Install Sublime Text on Mac OS X?


Step 1 – We need to visit Sublime Text website to download the software. Visit sublimetext.com


How To Install Sublime Text on Mac OS x?


Step 2 – After you are on sublimetext.com we need to click on the Download menu item on the top menu bar of the their website.


How To Install Sublime Text on Mac OS x?


Step 3 – We are going to download Sublime Text 3 it is still beta but since it is going to be the future of Sublime Text we should get use to it.  Click on Sublime Text 3 about two paragraphs down.


How To Install Sublime Text on Mac OS x?


Step 4 – Click on the OS X link to begin the download.


Step 5 – Locate your download of Sublime Text 3 probably in your download folder.


Step 6 – Slide the Sublime Text logo into your applications folder


Install Sublime Text on Mac OS X


Step 7 – Open your application folder and locate Sublime Text and open your Sublime Text.


Step 8 – This step is optional we will be using Sublime Text often so we suggest you keep it in the dock.  Right click on the Sublime Text Logo in your dock and go to options keep in dock.


 


Now that you have complete the Python Tutorial How to Install Sublime Text on Mac OS X we can move on to more in depth Python tutorials.  If you have any questions leave a comment below.



rm - Python Tutorial

rmrm – Remove files via the command line in the terminal.  This command gives us the ability to quickly remove files from our computer.  You need to be careful when using the rm command there is no way to recover the files once they are rm.


rm Examples


#Remove a file using the rm command
Thomass-MBP:test Tommy$ ls
test.py test1.py test2.py test3.py
Thomass-MBP:test Tommy$ rm test.py
Thomass-MBP:test Tommy$ ls
test1.py test2.py test3.py

#Remove multiple files using rm
Thomass-MBP:test Tommy$ ls
test1.py test2.py test3.py
Thomass-MBP:test Tommy$ rm test1.py test2.py test3.py
Thomass-MBP:test Tommy$ ls
Thomass-MBP:test Tommy$

 




rm