Welcome to the Python Introduction Homepage, Guest!
Python is a great high level programming language. It was developed by Guido Van Rossum during the late 1980's. Python is a all purpose programming language that boasts many interactive capabilities. Python is a fully object oriented programming language that is fully interpreted. Python 3 was introduced in 2008, but the community has been slow to adopt 3 fully. Python dev's respond to this slow paste with, "There should be one -- and preferably only one -- obvious way to do it." Therefor, I've chosen Python 3 as my development tool because I wish to further progress on Python. If we hold onto the past, python 2.7, etc, then we will never grow as a community.
This tutorial, of sorts, will detail Python 3.5, which is the latest Python version at the time of the Meraki site creation. Python 3 has a lot of similarities to versions lower than 3.5. This page will walk you through getting started using Python 3, and help you begin writing your first Hello World program!
The user can enter python commands directly into a Python prompt, and the interpreter will interact directly with the user to write Python programs.
What do you mean by High Level???
Programming languages are categorized into levels; low, mid, and high level. Low level languages are the lowest level of programming code a computer will understand, Machine code. Machine code is a programming language that is built upon binary or hexadecimal numbers. All computers can understand and directly interact with machine code. Mid level code is the assembly language level. The high level holds languages such as C++, C#, Java, Python, and more. Python is a advanced high level language, and is extremely easy to begin to understand programming with. Python's high level attribute creates a very simplistic way to program for beginners.
Object oriented programming, OOP, is a type of computer programming. The programmer must program the data types with accompanying data structures, and the programmer must import or define their own functions to be applied to the data structures written. The data structure becomes an object which contains data and functions to be used. The object orientation model creates a relationship between one object and another one through inheritance. The characteristics of a parent object can be inherited by the children of the object. Python fully supports the OOP technique that will encapsulate the code written within objects inside Python. Some object oriented terminology consists of:
A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.
A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are.
A class variable or instance variable that holds data associated with a class and its objects.
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
A variable that is defined inside a method and belongs only to the current instance of a class.
The transfer of the characteristics of a class to other classes that are derived from it.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
The creation of an instance of a class.
A special kind of function that is defined in a class definition.
A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
The assignment of more than one function to a particular operator.
Compiled languages looks at the entire code, and creates a machine code representation of the code being compiled. The machine code is made up of ones and zeros. The code is made into an executable file and ran. One advantage to compiling code opposed to interpreting the code is when you want to perform a task over and over again. The execution time will be much lower if the code is compiled opposed to being interpreted because it is already in machine code, and does not require being interpreted every single time the program is run.
The python file is run and read line by line individually and executes the commands that are found. Interpreted languages take each individual line and compile line by line until the end is reached. Python is primarily interpreted, especially if you follow this tutorial, but Python can be compiled and run too. Python is formally processed at run time by the installed interpreter.
How to obtain Python 3.5
The first thing you want to do is install python onto your system.
- Visit the Python Website
- Download Python 3.5 for your particular operating system
- BE SURE TO install python somewhere you will be able to find it easy
- The location will be needed later on in the installed, trust me.
- For Windows Users: Definitely install for all users
- Finish the installation and restart your system
- Python 3.5 and other versions of Python can run, but that is advanced and looking way ahead
IDE?? Command Prompt??
This tutorial will use the IDE PyCharm, which is free to students and faculty. You can alternatively create .py files using a text editor, like notepad++, and run the files using a command prompt. You need to look up how to change directories and show the contents of the directories on your specific system. Change into the directory of the py file you created using the text editor and type -> python3 run filename.py
The user can go Here to obtain more information on installing Python onto other operating systems.
Pycharm is my choice for IDEs. Pycharm has everything a user needs to run python scripts and any server related ideas you might have!
Pycharm provides each student and faculty with a year subscription to their service free of charge upon verification of their institutional credentials. Pycharm also provides a 30 day evaluation trial if needed. Once you have PyCharm downloaded, install the Pycharm onto your system. Keep the default settings unless you are sure you know what you're doing, mate. Once, the installation is complete, go ahead and restart your system to ensure all changes are in order. Pycharm should've picked up on the fact that you have Python3.5 installed, but if not, when we create a New Project we will see how to accomplish that.
Pycharm Installation Cont...
Once PyCharm is up and running, click on File at the top left, then new project, and Pure python. Pycharm shows you two options at the top: Location and Interpreter. The Location is just the absolute path to the file being saved. The default usually names the file untitled.py unless specified otherwise. The Interpreter correspondes to where you installed Python 3.5 on your system. I told you that you would need to know the location of Python, didn't I? Click create at the bottom right of the widget window. Now...
Once you click on Python File, you will be prompted to enter a name, enter hello_world and click ok.
type this into the white space print("Hello World, I've made my first Python program!")
Now...Right click on hello_world.py and Run 'hello_world'
Congratulations, you have officially created your first python program, sort of. :D
Advanced Beginners material
From here on we will use a main function that will act like a main function in Java or C++. So, delete your print statement inside the python file, and type the following in:
name = input("Enter your name: ")
mood = input("How are you feeling today: ")
your_name = my_name()
print("Hello " + str(your_name) + "!")
your_mood = my_mood()
print("Well, today is just going to get better, I promise!")
if __name__ == "__main__":
Make sure that there is two spaces between each function and two at the end after main()
We are defining two functions, my_name and my_mood, which prompts the user for his/her name and his/her mood The responses are saved as string variables and returned back to be saved as variables themselves. The variable your_name is saved as whatever you entered as your name, and the same goes for your_mood. We will discuss exactly why you need two spaces in the syntax page for Python.
Next, is the syntax part of Python
We will discuss the basic syntax rules of Python, and dive into what that __name__ == __main__ junk is all about, Guest