Do you want to start learning programming? Learning to code can be very difficult, and you probably think that you will have to attend classes for this. While this is true for some programming languages, there are also a large selection of languages that take only a couple of days to learn the basics. Python is one such language. In just a few minutes, you can write a simple Python program and run it. Let's get started.
Steps
Part 1 of 5: Installing Python (for Windows)

Step 1. Download Python for Windows
The Python language interpreter for Windows can be downloaded for free from the Python website. Make sure to download the version that is compatible with your operating system.
- You should download the most recent version available, which is 3.4 at the time of this writing.
- OS X and Linux come with Python already preinstalled. You don't have to install any Python-related software, but you will most likely need a text editor.
- Most Linux distributions and OS X versions still use Python 2. X. There were several changes between versions 2 and 3, especially regarding the "print" statement. If you would like to install a newer version of Python on OS X or Linux, you can also download the corresponding files from the Python site.

Step 2. Install the Python interpreter
Most users can install the interpreter without changing any settings. You can integrate Python into the command line by enabling the last option in the list of available modules.

Step 3. Install a text editor
While you can write Python programs in Notepad or TextEdit, you will find that it is much easier to read and write code using a specialized text editor. There is a huge selection of free editors such as Notepad ++ (for Windows), TextWrangler (for Mac), or JEdit (for any system).

Step 4. Make sure the installation was successful
Open Command Prompt (Windows) or Terminal (Mac / Linux) and type python. Python will be loaded and its version number will be displayed. You will be taken to the Python interpreter command line, denoted >>>.
Type print ("Hello world!") And press ↵ Enter. You should see the text Hello world! Displayed below the Python command line
Part 2 of 5: Basic Concepts

Step 1. Understand that Python does not require compilation
Python is an interpreted language, which means that you can run the program immediately after making changes to its file. This leads to the fact that the completion, processing and debugging of programs is much faster than in many other languages.
Python is one of the easiest languages to learn, and you can write and run a simple program in just a few minutes

Step 2. Understand the interpreter
You can use the interpreter to test your code without adding your program yet. This is very useful for learning how specific commands work and for writing test programs.

Step 3. Learn how Python works with objects and variables
Python is an object oriented language. This means that everything in the program is treated as objects. This means that you do not need to declare variables at the beginning of the program (you can do this at any time), and you do not need to specify the type of the variable (integer, string, etc.).
Part 3 of 5: Using the Python Interpreter as a Calculator
Performing some basic computational functions will allow you to understand Python syntax and how numbers and strings are handled.

Step 1. Start the interpreter
Open a command prompt or terminal. Type python and press ↵ Enter. The Python interpreter will be loaded and you will be taken to its command line (>>>).
If you have not integrated Python into the command line, you will need to navigate to the Python directory to run the interpreter

Step 2. Perform basic arithmetic operations
You can easily use Python to do basic arithmetic. In the window below, you can see some examples of how to use the calculation functions. Note: # denotes comments in Python code, and comments are not passed to the interpreter.
>>> 3 + 7 10 >>> 100 - 10 * 3 70 >>> (100 - 10 * 3) / 2 # Division always returns a floating point number (decimal) 35.0 >>> (100 - 10 * 3) // 2 # Integer division (double slash) discards the fractional part 35 >>> 23% 4 # This is the remainder of division 3 >>> 17.53 * 2.67 / 4.1 11.41587804878049

Step 3. Calculate the power of the number
You can use the ** operator to indicate exponentiation. Python can compute large numbers quickly. See the example in the window below.
>>> 7 ** 2 # 7 squared 49 >>> 5 ** 7 # 5 to the power of 7 78 125

Step 4. Create and modify variables
To perform basic algebraic operations, you can assign values to variables. This is a good introduction to how to assign values to variables in Python. Variables are assigned values using the = sign. See the example in the next window.
>>> a = 5 >>> b = 4 >>> a * b 20 >>> 20 * a // b 25 >>> b ** 2 16 >>> width = 10 # Variable name can be any string >>> height = 5 >>> width * height 50

Step 5. Close the interpreter
Once you're done using the interpreter, you can close it and return to the command line by pressing Ctrl + Z (Windows) or Ctrl + D (Linux / Mac) and then pressing ↵ Enter. You can also type quit () and press ↵ Enter.
Part 4 of 5: Create your first program

Step 1. Start your text editor
You can quickly create a test program to help you understand the basics of creating and saving programs and then running them in an interpreter. This will also help you make sure that the installation of the interpreter was successful.

Step 2. Write the "print" statement
"Print" is one of the main functions in Python and is used to display information in the terminal while a program is running. Note: "print" is one of the significant changes in Python 3. In Python 2, you only had to type "print" and then what you want to display. In Python 3, "print" has become a function, so you should write "print ()" with what you want to display in parentheses.

Step 3. Add your operator
One of the easiest ways to test a programming language is to display the text "Hello world!" Place this text inside the "print ()" statement, including the quotation marks:
print ("Hello world!")
Unlike many other languages, you do not need to end lines with;. You also don't need to use curly braces ({}) to denote blocks of code. Instead, padding will indicate what is included in the block

Step 4. Save the file
From the File menu of your text editor, select Save As. From the drop-down menu under the name field, select Python file type. If you are using Notepad (which is not recommended), select All Files and then add.py at the end of the file name …
- Make sure to save the file to an easily accessible location, as you will be navigating there using the command line.
- For this example, save the file as "hello.py".

Step 5. Run the program
Open a command prompt or terminal and navigate to the location where you saved the file. Once you've navigated to the correct folder, run the file by typing hello.py and pressing ↵ Enter. You should see the text Hello world! Displayed below the command line.
Depending on how you installed Python, you may need to type python hello.py or python3 hello.py to run the program

Step 6. Test frequently
One of the biggest benefits of Python is that you can test your new program instantly. It is advisable to keep the command line running at the same time as your text editor. By saving changes in the editor, you can immediately run the program from the command line and test the changes.
Part 5 of 5: Writing Complex Programs

Step 1. Experiment with control statements
Control statements let you control what a program should do under certain conditions. These operators are the backbone of Python programming, and they allow you to create programs that do different things based on inputs and conditions. Let's start with the while statement. In this example, you will be able to use the while statement to calculate the Fibonacci series up to 100:
# Each Fibonacci number is # the sum of the previous two numbers a, b = 0, 1 while b <100: print (b, end = '') a, b = b, a + b
- The loop will run as long as (while) b is less than (<) 100.
- The output will be 1 1 2 3 5 8 13 21 34 55 89
- The end = '' command will print the result on the same line instead of printing each value on a separate line.
- This simple program has a couple of things to look out for to create complex Python programs:
- Pay attention to the indentation.: indicates that the next line will be indented and will be part of the code block. In the example above, print (b) and a, b = b, a + b are part of the while block. Correct indentation is essential for your program to work.
- Several variables can be defined on one line. In the example above, a and b are both defined on the first line.
- If you enter this program directly into the interpreter, you must add a blank line at the end so that the interpreter knows that the program has finished.

Step 2. Define functions within the program
You can define functions that you will call later. This is especially useful if you need to use multiple functions within a large program. In the following example, you can create a function to calculate the Fibonacci series, similar to the one you wrote earlier:
def fib (n): a, b = 0, 1 while a <n: print (a, end = '') a, b = b, a + b print () # Later in the program, you can call the desired function # Fibonacci for any given value fib (1000)
It will return 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

Step 3. Create a more complex program with control statements
Control statements allow you to set special conditions that change the way the program is executed further. This is especially important if you are dealing with user input. In the following example, we will use the if, elif (else if), and else statements to create a program that estimates the age of a user.
age = int (input ("Enter your age:")) if age <= 12: print ("It's great to be a child!") elif age in range (13, 20): print ("You are a teenager!") else: print ("Growing time") # If any of these statements are true, # a corresponding message will be displayed. # If none of the statements are true, # the message "otherwise" will be shown.
- This program also introduces a few more very important operators that will be very useful in most different applications:
- input () - the operator expects keyboard input. The user will see a message written in brackets. In this example, input () is wrapped inside an int () function, which means that all input will be treated as integers.
- range () - This function can be used in many different ways. In this program, it checks if a number is in the range from 13 to 20. The final value of the range is not taken into account in the calculations.

Step 4. Explore other conditionals
In the previous example, the less than or equal to (<=) character was used to determine if the age entered meets a specified condition. You can use the same conditionals as in math, but the spelling is slightly different:
Meaning | Symbol | Symbol in Python | |
---|---|---|---|
Less than | < | < | |
More than | > | > | |
Less than or equal to | ≤ | <= | |
More or equal | ≥ | >= | |
Equals | = | == | |
Not equal | ≠ | != |
Step 5. Continue your study
Only the basics of Python are listed here. Although it is one of the easiest languages to learn, it does have a lot of digging if you're interested. The best way to keep learning a language is to keep creating programs! Remember that you can quickly write programs right in the interpreter, and testing your changes will be as easy as running a program from the command line.
- There are many good books on Python programming, including Learn Python and Program Python (Mark Lutz), Geo-Application Development in Python (Vestra E.), Introduction to Machine Learning with Python (Andreas Müller, Sarah Guido), "Python in UNIX and Linux System Administration" (Noah Gift, Jeremy M. Jones) and others.
- There are many sources on the Internet, but most of them are focused on Python 2. X. You may need to make adjustments to the examples provided there.
- Many programming courses offer Python classes. Python is often taught in introductory classes, as it is one of the easiest languages to learn.