What is python and what are its benefits
Python is a high-level programming language that is used to code everything from web applications to machine learning algorithms. It’s easy for beginners to learn and has some unique features such as an interactive environment and automatic memory management. Python is incredibly popular and widely used because of its ease to use, powerful libraries and a friendly community.
What is Python?
Python (from ‘python’s eye’) is a general-purpose programming language that has first been created by Guido Van Helten in 1991. The name ‘Python’ stands for ‘Python Programming Language’. Python is a simple, elegant and powerful programming language that can be used to code anything from websites to complex software applications.
How to install python on your computer
Windows: Download and run the Python setup installer. Mac OSX/Linux: Open up a terminal, cd to the directory you downloaded the Python installer to and type run python3.3.5.If you get an error, try using the file name instead of the full path, or try using python3 instead.
Once you have Python installed, you can make a new file for your first program. Type in your code and run it!
import random print (random . randint ( 1 , 20 )) import time start = 0 end = 20 num_seconds = 7 sec = 0 while start <= end : sec += 1 if sec > num_seconds : break start += 1 print ( “Time: ” , time . strftime ( “%H:%M:%S” , time . localtime ()), “Secs” , sec ) print ( ‘Program finished in’ , num_seconds , ‘seconds.’ )
Basic syntax and programming concepts
In Python, you type everything in lowercase. Indentation is used to determine the syntax of a program and should be used as it is in the example below. A triple underscore (“__”) at the beginning of a case means that whatever is there is hidden. A single underscore (“_”) on the other hand means it is something you can see and change. Strings begin and end with quotation marks. Numbers do not, but they should be surrounded by either a single or double quotation mark.
Arithmetic operations are performed on numbers. However, you can use a single letter or group of letters to denote an operation as well. So “+” would add two numbers, “-” would subtract one number from another, “*” would multiply numbers and so on. The operators are all lowercase and you can mix operators with numbers or other operators in the same statement.
You can also use Python to make functions. You can therefore think of a function as something that you do within a program to add or subtract certain values or perform mathematical operations or create lists. A function can take as many or as few arguments as you wish. It is like putting a function in a box and taking out whatever it needs to do the job.
Examples of programs that can be written in python
The following is an example of a program written in Python. It is a simple program that prints the numbers 1, 2 and 3. It does this by having a for loop, which means “for each” and a while loop. A for loop is used to run through a section of code over and over again. When it reaches the end of the “for” statement, it looks at what comes next and keeps running the inner while loop until it reaches the end of that statement or breaks out with a break statement. The new statement tells it to create a new iteration of the loop and keep going. The break statement stops the loop and goes to the next part of the code. So in this example, it keeps looping until all the numbers have been printed.
An example of a program written in Python:
for i in range(1,4):
sys.stdout.write(str(i) + ” “)
Below is a definition of each term used in the above example:
import sys statement: This tells Python to use a module called sys that has extra commands.
statement: This tells Python to use a module called that has extra commands. range(1,4): This tells Python to go through the list of numbers 1 2 3 4 and choose which one to pick:
This tells Python to go through the list of numbers and choose which one to pick: sys.stdout.write(str(i) + ” “): This takes the number i , puts it into a variable called str and then uses that variable as output.
This takes the number , puts it into a variable called and then uses that variable as output. break: This tells Python to stop the loop.
How to find help and further resources for learning python
The first place to turn to is the official Python website. This is a great place to go for help and further resources. The site even has a forums where you can ask questions and receive help from Python developers around the world (or at least those who use the website and are willing to give advice). Another great resource is Python’s official documentation. It’s a thorough guide to Python, its syntax and overall use. It also serves as an excellent reference.
Another useful resource is the Python wiki. This is a database of Python’s documentation that anyone can edit and contribute to. The information on this database is up to date and very helpful, especially in finding help and further resources for learning the language. As a site like this grows in size, it will become even better (both for finding help and further resources for learning python, but also for its own sake).