Python Guide Clear Introduction to Python Programming and Machine Learning Alex Campbell Python Guide Table of Contents BOOK 1 Python Computer Programming: Simple Step-By-Step Introduction to the Python Object-Oriented Programming. Quick Start Guide for Beginners. BOOK 2 Python Machine Learning: Complete and Clear Introduction to the Basics of Machine Learning with Python. Comprehensive Guide to Data Science and Analytics. Python Computer Programming Simple Step-By-Step Introduction to the Python Object-Oriented Programming Quick Start Guide for Beginners Alex Campbell
P ython is one of the most powerful computer programming languages of all time, for several reasons well discuss in the first section. The syntax is simple to learn and use and, compared to other programming languages, you often dont need to write so much code.
The sheer simplicity of the language helps programmers write more and develop programs that are more complex in less time. This guide provides all you need to master the basics of programming with Python. I have kept it deliberately simple it is a quick-start guide, after all. I have provided plenty of coding examples to show you how the syntax works, too, along with a guide on installing Python on Windows, Mac, and Linux systems. I finish with some useful tips on helping you to code better. By the end of the guide, you will have a deeper understanding of the Python language, a stepping stone from which to take your learning further.
Please note that we are using Python 3 in this guide, not Python 2, as many similar guides do. Are you ready to become a computer programmer? Lets get started on this wonderful journey.
P ython is the brainchild of Guido Van Rossum and is a simple, all-purpose programming language. It is known for its easy syntax, easy-to-read code, and, for complete beginners to computer programming, it is one of the best to start with. Learning Python allows you to do many things, and there are several advantages to using it.
That means an interpreter is used to parse any program you write, one line at a time.
With compiled languages, such as the C languages, a compiler is used to compile the code before it is executed or run. So, what is the difference? Interpreted computer languages are a little slower than compiled languages and dont offer the performance benefits of compiled languages. However, the latter are too difficult and complicated for complete beginners to learn, and they require you to write every function, even the most basic ones. Advanced programming tasks sometimes require you to encapsulate data by creating data structures too. In a compiled language, therefore, all the small details must be taken care of before you can even begin to solve the problem the code is written for. With interpreted languages, you dont define data structures, and you dont define any of the smaller functions because Python does it all for you.
Plus, you can make use of the multitude of libraries included with Python without having to write reams of code.
Unlike compiled languages, with Python, there is no need to define the data type of a variable before you need it. Python can infer it automatically based on the value type in the variable. For example: myvar = "Good Morning Python." In the above code line, we have a variable called myvar, and a string of Good Morning Python is assigned to it. That means myvar has a data type of a string. Also, note that Python does not require a semicolon (;) at the end of a statement.
Compiled languages do require this, and it is one of the most significant areas where errors occur forgetting to add semicolons can throw up all kinds of errors in the code. Lets say that, a bit later, we wanted a value of 1 assigned to myvar: myvar = 1 What does that do? It makes the variable into an int (integer) type.
If you have written any programs in JavaScript or PHP, you probably spotted that both will automatically convert the data in one data type into other types. For example: JavaScript 1 + "2" Would be treated as 12. 1 gets converted into a string type and is concatenated (joined) to 2, thus the result of 12 that is a string. Python does not allow automatic conversions so the same code: 1 + 2.
Would result in an error like this: Traceback (most recent call last): File "main.py", line 2, in 1 + "2"
- Less Code = More Achievement
Python uses far less code to achieve what other programs do; for example, it uses around one-third or one-fifth less code than Java. You need only two lines of code to read Python files: with open("myfile.txt") as f: print(f.read()) For example: # these lines create a "myfile.txt" file containing the data Lets Learn Python with open("myfile.txt", "w") as f: f.write("Lets Learn Python") # Both lines will read the data from myfile.txt with open("myfile.txt") as f: print(f.read()) And the output would be: Lets Learn Python Dont worry too much about the commands used for reading and writing a file; I will cover it all as the book progresses. Who Uses Python? Many of the largest names use Python, such as NASA, Google. HortonWorks, Quora, and many others. Do you want to know what you can build with it? Just about anything, including:
- Web applications
- GUI applications
- Data scraping from a website
- Data analysis
- Developing games
- Building utilities for system administration
- And much more
Now you know what Python is and what you can use it for, well turn to setting up your environment and installing it on Windows, Mac, and Linux systems.
Installing Python 3 - Windows
T he first step is to download Python onto your Windows machine, so head to https://www.python.org/downloads and download the latest version for Windows.
During the download, you will see a Customize Python window make sure the option to Add Python.exe to Path is checked. Once you have installed Python, open a command prompt on your Windows PC either open the search box in the Start menu and type in cmd or open the Start menu, click on Windows System>Command Prompt. At the command prompt, type in python The Python shell opens; type the following to check it all works: print("Good Morning World") You will see the following on your screen: Good Morning World Installing a Text Editor You require a text editor to write programs in Python, and you can use any one you want. Notepad is already included with Windows, but a better one is Notepad++ or even Sublime Text. Make your choice and download it via the internet. After weve looked at the other platforms, well move on to running Python programs.
Next page