Start coding with python
Introduction
If you've decided to learn Python for software development, data science, or another domain, you're probably wondering where to start. You don't need a specialized IDE (or integrated development environment) like PyCharm or a super-computer with tons of RAM to get started. All you need is your favorite text editor and a few minutes of your time. Follow these instructions to install Python before getting started on our Beginner Learning Pathway!
Install Python.
Install Python
You can download Python from the official website (https://www.python.org/downloads/) and install it in any of the following ways:
To install Python on Windows or Mac OS X, double-click on the downloaded file to launch an installer application. Follow the instructions to complete the installation process.
You can also use a terminal window or command line prompt to run a script that will download and install Python for you:
On Windows, open an administrative command prompt (right click Start -> Run -> cmd). Then, type "cd C:\Python27" to navigate to your default Python installation location (this should be C:\Python27), and then type "python get-pip.py". If you are using another version of python (such as 32) , just change 27 with whatever version number is appropriate for your system; e g , if you want 64 bit python on 64 bit windows 7 , then enter c:\Python64\get-pip .py instead of c : \P ython27\ge t - pip . py . Also note that if you have installed multiple versions of python , then choose one at a time for installing pip so as not t o overlap different installations .
Download the free VS Code editor.
Start by downloading the free VS Code editor. It can be installed for Windows, MacOS, and Linux.
Once you have it installed, open the editor and create a new file (Ctrl+N).
In this file, type: print('hello world')
Save your file as "hello_world" in C:\Users\yourName\Documents or something similar if you're on a Windows computer; then run it by pressing Ctrl+R (or selecting View > Reload Window)
Launch VS Code.
Now that you've got a basic understanding of how to run Python code, let's walk through the steps necessary to build a project. First, open VS Code and open the folder where you'd like to create your project. Then, open the terminal if it isn't already open by clicking on View > Integrated Terminal (or pressing Ctrl+`). Next, type “code .” in your terminal and hit enter. This will navigate into your current folder where you can start creating files for your project.
Once in the folder where you want your code files saved, open up Command Palette by going up to View > Command Palette (or pressing Ctrl+,) and then type “python” into the search bar at the top of Command Palette window. Select “Launch Python Interactive Window” from this list of options and give it another try!
Create your first Python file.
Create a new file
Open VS Code, then create a new file by selecting File->New File. This will open up the editor where you can type in some code and save it as a Python file.
Type in some code
The first thing to do is type in some basic Python code: "print('Hello World')". You should see an output saying 'Hello World' when you run or debug your program (see below). It's important to realize that this isn't an executable program yet; we need to add more things like variables and functions before we can run the program without errors! It's also good practice for us to use comments so other people understand what our code does even if they don't know Python already - don't worry about making these too long though because nobody else needs them besides yourself :). We'll be adding more comments as we go along so keep checking back every few lessons!
Open a Terminal in VS Code.
You'll need to open a terminal in VS Code. If you're on Windows, the fastest way to do this is by pressing Ctrl+` (that's the tilde character) and then typing "code .." followed by Enter.
This will open a command line in VS Code where you can run python commands. Alternatively, if you're on Mac or Linux, click the Terminal button in your menu bar at the top left of VS Code.
Once you've got your terminal window open we'll run Python's built-in interpreter directly from there using the command:
python -V
And we should see something like this:
Python 3.7.0rc1; Anaconda 4.5.1 (64-bit)
Install a linter extension to help spot syntax errors in your code.
A linter is a tool that will scan your code for syntax errors. It also helps you write consistent, idiomatic code.
You can install a linter extension for your favorite text editor or IDE (a program used to write and edit code). For example, this tutorial uses VSCode. Check out the extension marketplace for more information about available extensions!
Linting your code can help you catch mistakes and poor practices before they become problems! A linter will flag problems quickly so that they don’t get out of hand into major bugs or worse. In addition to catching syntax errors, linters provide useful feedback on best practices by highlighting common problems in the language itself--for example, alerting you if you misspelled an important keyword like “print” or “class” in Python.
Run your code.
Run your code in the terminal.
Run your code in a Python shell,
Run your code in a Python editor,
Run your code in an IDE (Integrated Development Environment), or
Run your code using a Jupyter notebook.
Now that you have your environment set up, it's time to start coding!
You can use python to do anything you want. It doesn't matter if you are just starting out as a programmer or if you have been doing it for years, python will be able to help you create whatever it is that is on your mind. For example, we could make some websites with python, and they would look like this:
[here](https://getpython3.com/) is an easy website that uses HTML and CSS (a language that makes web pages look pretty)
[here](https://www.pythonforbeginnersbook.com/) is another website with HTML and CSS
You can also use python to make games! Here's an example:
[here](https://pygame-projects.github.io/wp-content/uploads/2016/09/PyGame_ScrollingText1_1024x768_800x600_640x480_.png) is some text moving across the screen in a game made with pygame
Conclusion
Don't let this intro get you down. Python is a great programming language to have at your fingertips, and now that you've got it installed and running, it's time to start coding! Now, we only really scratched the surface of what Python can do in this post. If you're looking for ways to practice and improve your skills, check out some of our other free tutorials and resources.
Comments
Post a Comment