Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python: By: Borhan Almalek

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Python

By :
Borhan Almalek

The Python programming language is


freely available and makes solving a computer problem almost as
easy as writing out your thoughts about the solution. The code can be
written once and run on almost any computer without needing to
change the program.
How Python Is Used
Python is a general-purpose programming language that can be used
on any modern computer operating system. It can be used for
processing text, numbers, images, scientific data and just about
anything else you might save on a computer. It is used daily in the
operations of the Google search engine, the video-sharing website
YouTube, NASA and the New York Stock Exchange. These are but a
few of the places where Python plays important roles in the success
of the business, government, and non-profit organizations; there
are many others.

Python is an interpreted language. This means that it is not


converted to computer-readable code before the program is run but
at runtime. In the past, this type of language was called a scripting
language, intimating its use was for trivial tasks. However,
programming languages such as Python have forced a change in that
nomenclature. Increasingly, large applications are written almost
exclusively in Python. Some ways that you can apply Python include:

 Programming CGI for Web Applications


 Building an RSS Reader
 Reading from and Writing to MySQL
 Reading from and Writing to PostgreSQL
 Creating Calendars in HTML
 Working With Files
How Does Python Compare to Perl?
Python is an excellent language for large or complex programming
projects. Integral to programming in any language is making the
code easy for the next programmer to read and maintain. It takes
great effort to keep Perl and PHP programs readable. Where Perl
gets unruly after 20 or 30 lines, Python remains neat and readable,
making even the largest projects easy to manage.

With its readability, ease of acquisition and extensibility, Python


offers much faster application development. In addition to easy
syntax and substantial processing abilities, Python is sometimes said
to come with "batteries included" because of its extensive library, a
repository of pre-written code that works out of the box.

How Does Python Compare to PHP?


The commands and syntax of Python differ from other interpreted
languages. PHP is increasingly displacing Perl as the lingua franca of
web development. However, more than either PHP or Perl, Python is
much easier to read and to follow.

At least one downside which PHP shares with Perl is its squirrely
code. Because of the syntax of PHP and Perl, it is much harder to
code programs that exceed 50 or 100 lines. Python, on the other
hand, has readability hard-wired into the fabric of the language. The
readability of Python makes programs easier to maintain and extend.

While it is starting to see more general usage, PHP is at heart a web-


oriented programming language designed to output web-readable
information, not handle system-level tasks. This difference is
exemplified by the fact that you can develop a web server in
Python that understands PHP, but you cannot develop a web server
in PHP that understands Python.

Finally, Python is object-oriented. PHP is not. This has significant


implications for the readability, ease of maintenance, and scalability
of the programs.
How Does Python Compare to Ruby?
Python is frequently compared to Ruby. Both are interpreted and
therefore high level. Their code is implemented in such a way that
you need not understand all the details. They are simply taken care
of.

Both are object-oriented from the ground up. Their implementation


of classes and objects allow for greater reuse of code and ease of
maintainability.

Both are general purpose. They can be used for the simplest of tasks
like converting text or for much more complicated matters such
as controlling robots and managing major financial data systems.

There are two major differences between the two languages:


readability and flexibility. Due to its object-oriented nature, Ruby
code does not err on the side of being squirrely like Perl or PHP.
Instead, it errs in being so obtuse that it is often unreadable; it tends
to presume upon the programmer's intentions. One of the chief
questions asked by students learning Ruby is "How does it know to
do that?" With Python, this information is typically plain in the
syntax. Aside from enforcing indentation for readability, Python also
enforces transparency of information by not assuming too much.

Because it does not assume, Python allows for easy variation from
the standard way of doing things when needed while insisting that
such variation is explicit in the code. This gives power to the
programmer to do whatever is necessary while ensuring that those
who read the code later can make sense of it. After programmers
use Python for a few tasks, they often find it hard to use anything
else.
How Does Python Compare to Java?
Both Python and Java are object-oriented languages with substantial
libraries of pre-written code that can be run on almost any operating
system. However, their implementations are vastly different.

Java is neither an interpreted language nor a compiled language. It is


a bit of both. When compiled, Java programs are compiled to
bytecode—a Java-specific type of code. When the program is run,
this bytecode is run through a Java Runtime Environment to convert
it to machine code, which is readable and executable by the
computer. Once compiled to bytecode, Java programs cannot be
modified.

Python programs, on the other hand, are typically compiled at the


time of running, when the Python interpreter reads the program.
However, they can be compiled into computer-readable machine
code. Python does not use an intermediary step for platform
independence. Instead, platform independence is in the
implementation of the interpreter.
What is Python?
Python is an open-source, object-oriented and a high-level programming
language for web and app development. The language is very simple and
easy to learn. Hiring mid-level experienced python can prove very cost-
effective, greatly reducing the overall cost of the project. Apart from this,
it allows developers to write complex codes in simple steps. The
language was founded by developer Guido Van Rossum in 1991, whether
it is data science, big data, or web development, Python is a popular
choice amongst developers.

Why Python is popular?


Python has witnessed incredible growth from the past few years, mainly
due to its simple learning, versatility, and efficiency. It is a general-
purpose language, designed specifically to be simple to read and write.
Furthermore, the language has become a universal platform for various
development requirements, and it offers a lot of options to the
programmers in general. Other than its easy to use and learn
functionality, it offers a mature and supportive python community, which
guides developers in the right direction.

Python comes with many libraries ranging from pandas, requests,


Numpy, SQLAlchemy, etc. Numerous libraries make Python a top choice
for the developers, as having that many libraries, gives it an advantage
over other programming languages. It is an open-source language with a
few lines of code which makes it a highly productive language in web
development.
Top features of Python
• Easy to use and learn
• Supportive Python community
• Numerous libraries
• Efficient and fast language
• Most Preferred language
• Flexible Language
• Python in Academics
• Automation of tasks
• Python is a versatile language

Easy to use and learn programming language


Python is easy to learn, and it’s easy to use, making it a top choice for the
newcomers. Python is considered one of the most accessible
programming languages, as it offers simplified syntax, and emphasize
more on natural language. Python codes are easy to write and can be
executed faster. One of the top reasons that contribute to the popularity of
python is that it could be easily read by amateur developers as well.

Professional and supportive Python community


There is a professional Python community on Python, it offers plenty of
guides, and video tutorials and tips, to the learners of any skill level or
age. It’s true that if a programming language does not have a proper
community, it won’t grow. The Python community is one of the most
active communities amongst all programming languages. If anyone wants
any tip or has an issue, he or she can get support from online forums.
Most top Python developers are well versed in web development services
and skills and are active participants on these forums.
Numerous Python Libraries and frameworks
Python offers many libraries and frameworks, which save time and effort
in the initial phase of development and this is one of the top reasons why
python is one of the most preferred development languages. Python
offers cloud media services and comes with cross-platform support with
library like tools, they both prove to be extremely beneficial when used
together.

Many libraries are available for python language, like:

• matplotlib for creating charts and graphs


• SciPy for engineering applications
• Beautiful Soup for HTML and XML parsing
• NumPy for complex scientific computing
• Django is an all in one package for server-side web development

Efficient and Faster than most modern languages


Python is an efficient language and much faster than many other
technologies. With its versatility Python can be used for any kind of
environment, be it mobile applications, desktop applications, or web
development. The versatility of python makes it a lucrative option for the
developers.

Most Preferred language


Python is in high demand for its incredible features and versatility.
Companies offering python development services prefer employees with
skills in machine learning, hence making python truly commendable for a
developer who is looking forward to working in machine learning.
Flexible Language
Developers can easily try something new using python as it is very low
on restrictions. They can build any sort of application on Python, which
is not possible with most of the other programming languages. For those
who love to work in new technologies, they can become experimental in
projects just by learning a single language.

Python in Academics
Python has made its mark in every industry and is slowly becoming an
important language to learn in schools and colleges. This is mostly
because it can be used in advanced technologies of the future, like
artificial intelligence, machine learning, data science, etc. Python has
become a vital part of the education industry, with more and more
budding developers choosing it as their choice of development language,
we assume its popularity will only increase in the time ahead.

Automation of tasks
Python can be an incredible help in the automation of tasks, it offers a lot
of tools and modules that make things less complex. Python is the best
language when it comes to the automation of software testing and the
developers will be surprised to work with a few lines to write codes for
the automation process.
Python is a versatile language
Python is an incredibly versatile development language; most other
programming languages don’t even come close to it. Besides versatility,
running codes in python is quick and it offers productive results. Python
is also known as a programmer-friendly language as it is very easy to use
and offers many other features that make web development efficient.

Python is growing at an incredible speed, it is a robust programming


language that offers easy usage of code lines, along with many other
incredible features. The language is being adopted as a career choice by
budding developers worldwide, thanks to its versatility and ease of
coding. With the capabilities that Python offers, and ease of hiring
Python developers, it is slowly becoming the top choice for developers
who are starting out with machine learning.

Data Science as a field has gained a lot of popularity in the recent, couple
of years. This field primarily deals with converting huge amounts of data
into meaningful marketing strategies. The data dealt with here, refers to
the scores and scores of records present online, these records could be
anything from a person’s shopping choices to daily notifications. This
data is gathered, structured and then studied to reach a logical conclusion.
While earlier, it was only the IT companies who were the forerunners in
this field, today there are companies across the field of finance, e-
commerce, retail, health care and more, dealing with data analytics. The
process of drawing value based insights from the unstructured data in the
virtual space, is known as data analytics. The professionals working in
this field are referred to as Data Scientists or Data Analyts and they make
use of certain tools to achieve end results.
These tools used for data analytics are namely, SAS Programming, R
Programming, Hadoop, Python, SQL and others.

Of these tools, Python is one such tool that has a unique attribute, of
being a general purpose programming language as being easy to use,
when it comes to analytical and quantitative computing. Python has been
in the industry for quite a long time and has been used in industries like
scientific computing, oil, gas, finance, physics, signal processing and
more. Python has also been used in building applications such as
YouTube, has been instrumental in powering Google’s internal
infrastructure and so on. This tool can coordinate massive clusters of
computer graphics servers and aid in the production of movies, this
attractive attribute is why companies like Disney, Sony, Dreamworks and
the likes depend on it.
When it comes to data science, Python is a very powerful tool, which is
also open sourced and flexible, adding more to its popularity. It is known
to have massive libraries for manipulation of data and is extremely easy
to learn and use for all data analysts. Anyone who is familiar with
programming languages such as, Java, Visual Basic, C++ or C, will find
this tool to be very accessible and easy to work with. Apart from being an
independent platform, this tool has the ability to easily integrate with the
existing Infrastructure and can also solve the most difficult of problems.
It is said, that this tool is powerful, friendly, easy and plays well with
others, apart from running everywhere. A lot of banks use this tool for
the purpose of crunching data, some institutions use it for analyzing and
visualization. This tool offers the great benefit of using one programming
language, across multiple application platforms.

Python has already been proven to be as good as R Programming is, in


terms of all the process under data analytics. Any novice, entering the
field of data analytics can use this programming language to get started
in the data science industry. As a result of its multipurpose uses, there are
a lot of institutes, which offer courses in Python.
A Python developer uses Python to build a piece of software according to
a project’s requirements. They are responsible for creating applications,
frameworks, tools, websites, web apps, AI-based applications, and many
other solutions.

Python developers are highly versatile and can bring value to a vast
number of projects. That’s because of the language’s flexibility that can
provide results for a considerable range of digital solutions. Such
possibilities are the reason why Python development services are among
the most demanded in the tech industry.

The business applications of Python cover an extremely wide offering.


From web development and GUI programming to Big Data and custom
enterprise solutions, it seems like Python applications get better and more
powerful every day. And thanks to powerful and constantly-evolving
frameworks like Django, CherryPy, Tornado, and Flask, there's still a lot
of room for growth.

That said, the most common uses for Python in business are Data
Science, Machine Learning, Backend Development, Game Development,
and Custom Enterprise applications. If you want to learn more, check out
this page on Python development services, where we take a deeper look
into Python programming and what types of applications can help your
business.
Python programming is exactly what it sounds like: developing software
with Python. However, there are many different ways to come about that.
For businesses, developing the best software with Python programming
always depends on having the best software developers available.

That's exactly why outsourcing Python programming has become such a


standardized practice in practically every industry. That way, any
business can develop high-quality Python applications and hire a custom
development team that matches the exact requirements of its project.

Facebook, Google, Dropbox, Spotify, Quora, Wikipedia, Netflix,


Yahoo!, NASA, and many other companies use Python due to the many
benefits it conveys. It is one of the most flexible, reliable, and capable
programming languages in the world, and it plays a major role in most
types of software development projects.

Simply put, python apps are universal. Companies across every industry
use Python code to create everything from simple lightweight
components to full-fledged enterprise applications. Paired with the proper
talent to support it, there is practically no limit to what python software
development can achieve.
The Python Programming Language
When we think about what Python is, there are three general
characteristics we can use to describe it:

1. High Level Programming Language


2. General–purpose
3. Open–source

Let's break each of these down.

High Level Programming Language


In computer science, a high level language is one that is relatively
easy for humans to intuitively understand and interpret. On the other
hand, low level languages are easier for a machine to read, but are
usually harder for the human programmer to understand.

This means that Python code is relatively programmer–friendly and


closer to human languages in how it's written. For example, if you look
at the Python code in the picture above, you'll see that a lot of the
words, or syntax, actually resemble real words we use in English such
as, "if," "return," and "True"!

Once Python code is written by a human, it then needs to


be translated by a machine back into a machine language so that it
can be understood and run by your computer (making it an
"interpreted language").
General-Purpose & Open-Source
General–purpose refers to how Python can be used for a variety of
programs and appplications. Rather than being specialized for a certain
field or domain (also known as "domain–specific"), Python can be
used to tackle a wide range of problems and build innovative solutions
for various technologies! We discuss some of these uses for Python
below.

Open–source means that anyone can openly collaborate on and


publicly contribute to the development of Python as a language.
Anyone is also able to download and use Python on their machine
regardless of their operating system, or OS.

Over the years, Python has become increasingly versatile as a coding


language. From basic programs such as printing the phrase “Hello
world!” to being used in data science and machine learning, more and
more Python libraries and applications are being expanded by open-
source contributors and used across different industries. The most
recent version of Python is version 3.8.

Continue reading to learn about Python's strengths and weaknesses, as


well as some of its common applications!
Pros & Cons
While Python is a popular language to both learn and use, the language
isn’t perfect. As with all computer science languages, Python has its
own unique shortcomings that companies and programmers often have
to work around.

Some of the pros and cons of Python are listed here, and explained
more below:

Pros Cons

Has a large community Slower speed

Easy to learn Design restrictions

Good for prototyping


The Pros of Python
Pro 1: A Large Community

Python is a language with a growing community of users. A simple


Google Search of any Python topic will display thousands of results
(and multiple Stack Overflow links) in response! There are many
Python tutorials covering a wide range of concepts online, for both new
and advanced coders to get help.

If there are bugs in your Python code, there’s a huge chance the same
problem has already been encountered and solved by someone else.
The growing community is also fostered by the fact that Python is also
an open-source language that can be used or contributed to by anyone
in the public.
Pro 2: Easy to Learn

Python is easy to read and quick to learn because it’s a high level
programming language. When it comes to scripting languages, it’s one
of the first languages taught in schools, and for good reason: Python
helps students to learn basic coding concepts without being
overwhelmed by how to write code, different data types, or memory
management.

We'll go over more about how to start learning Python further below.

Pro 3: Good for Prototyping


In industry applications, delivering a viable product is important. In
addition to being approachable for first-time coders, Python is also
great for newer developers because it's an easy language to learn,
interpret, and apply on the job.

When it comes to prototyping and creating models for production,


Python also allows programmers to build products at a faster pace than
other languages.
The Cons of Python
Con 1: Slower Speed
Python runs relatively slower than its popular counterparts, such as
Java and C++, because it is an interpreted language. Unlike the former
languages mentioned, it needs a Python interpreter to translate the code
for the computer to understand.

Python also takes care of allocating and deallocating memory rather


than putting this burden on the programmer. These two additional
factors slow down the program runtime, and most companies get
around this problem by creating more server space for their products to
run.

Con 2: Design Restrictions

Testing and debugging in Python can be difficult because some errors occur only
when a program runs.

Design restrictions can be a prominent con for many coders. Python


has errors that sometimes only occur when a program runs. This
characteristic makes testing and debugging a hassle at times.
However, new tools that allow programs to be run in chunks, such as
Jupyter Notebooks, can help resolve this issue.
Real World Python Applications
Python can be applied to multiple real world situations. If a problem
utilizes a lot of big data, artificial intelligence, web development/web
applications, or modeling, Python is one of the go-to languages used to
create deliverable results.

Read more in detail about the various real world applications of


Python, or explore a few of the industries that use Python below:

Tech
 Instagram uses Python and Django, a Python web framework,
for application development. For a rapidly growing company,
Python’s user-friendly aspect is important in order to make new
features come to life fast.
 Spotify has created their own in-house data analysis package
called Luigi, which uses Python to gather data about user
metrics in order to better curate custom playlists and mixes for
users.
 SurveyMonkey also uses Python to break down their main
features into smaller, more manageable APIs.
Finance
 Quantitative researchers at companies such as Citadel use
Python to create models that predict financial outcomes of
different industries. Because Python is a great language for
machine learning with some standard libraries specifically for
dealing with financial data, it’s a convenient option for these
firms.
 Commercial financial service companies (such as banks,
money transferring services, and budgeting apps) also use
Python to create frameworks for their apps and services.
Biotech
 Python is valuable in the field of bioinformatics, which also
involves a lot of data. Built-in Python packages such
as numpy, scipy, and pandas can be particularly useful for this
type of application.
 In many areas of academia that focus on computational
biology, Python comprises a significant part of many students'
research projects. The language can be used heavily for
modeling biological problems.
Learning Python
Among its various advantages, one of Python’s greatest strengths is
helping new coders learn basic concepts and become familiar with
programming. There are also many resources widely available to learn
Python.

As mentioned before, the language is easy to learn and is a great


starting point for any student aspiring to pursue an education or career
in coding, or even in jobs outside of tech companies such as in the
fields mentioned above.

Python Classes for Kids

At Juni Learning, we teach Python to aspiring young coders ages 11-


18, with the help of experienced coding instructors. From solidifying
coding basics, to building algorithms and analyzing datasets, these
courses explore the many different applications of Python and teach
students how to build their own coding projects.

Read more about our coding courses and curriculum, or register for
coding classes with our Admissions Team to learn which course is
best for your child’s coding journey.
The Programs

First : Program to calculate BMI

# getting input from the user and assigning it to user

height = float(input("Enter height in meters: "))


weight = float(input("Enter weight in kg: "))

# the formula for calculating bmi

bmi = weight/(height**2)
# ** is the power of operator i.e height*height in this case

print("Your BMI is: {0} and you are: ".format(bmi), end='')

#conditions
if ( bmi < 16):
print("severely underweight")

elif ( bmi >= 16 and bmi < 18.5):


print("underweight")

elif ( bmi >= 18.5 and bmi < 25):


print("Healthy")

elif ( bmi >= 25 and bmi < 30):


print("overweight")

elif ( bmi >=30):


print("severely overweight")
second: implement Snake Game

import pygame
import time
import random

pygame.init()

white = (255, 255, 255)


yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)

dis_width = 600
dis_height = 400

dis = pygame.display.set_mode((dis_width,
dis_height))
pygame.display.set_caption('Snake Game by
Edureka')

clock = pygame.time.Clock()

snake_block = 10
snake_speed = 15

font_style = pygame.font.SysFont("bahnschrift",
25)
score_font = pygame.font.SysFont("comicsansms",
35)
def Your_score(score):
value = score_font.render("Your Score: " +
str(score), True, yellow)
dis.blit(value, [0, 0])

def our_snake(snake_block, snake_list):


for x in snake_list:
pygame.draw.rect(dis, black, [x[0], x[1],
snake_block, snake_block])

def message(msg, color):


mesg = font_style.render(msg, True, color)
dis.blit(mesg, [dis_width / 6, dis_height /
3])

def gameLoop():
game_over = False
game_close = False

x1 = dis_width / 2
y1 = dis_height / 2

x1_change = 0
y1_change = 0

snake_List = []
Length_of_snake = 1

foodx = round(random.randrange(0, dis_width -


snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height -
snake_block) / 10.0) * 10.0
while not game_over:

while game_close == True:


dis.fill(blue)
message("You Lost! Press C-Play Again
or Q-Quit", red)
Your_score(Length_of_snake - 1)
pygame.display.update()

for event in pygame.event.get():


if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()

for event in pygame.event.get():


if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0

if x1 >= dis_width or x1 < 0 or y1 >=


dis_height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx,
foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]

for x in snake_List[:-1]:
if x == snake_Head:
game_close = True

our_snake(snake_block, snake_List)
Your_score(Length_of_snake - 1)

pygame.display.update()

if x1 == foodx and y1 == foody:


foodx = round(random.randrange(0,
dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0,
dis_height - snake_block) / 10.0) * 10.0
Length_of_snake += 1

clock.tick(snake_speed)

pygame.quit()
quit()

gameLoop()

You might also like