What is Python
Python is an interpreted scripting language developed by Guido Van Rossum known as the founder of Python programming.
Python is a general-purpose, dynamic, high-level, and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn and provides lots of high-level data structures.
Python is an easy to learn yet powerful and versatile scripting language, which makes it attractive for Application Development.
Python's syntax and dynamic typing with its interpreted nature make it an ideal language for scripting and rapid application development.
Python supports multiple programming patterns, including object-oriented, imperative, and functional or procedural programming styles.
Python makes the development and debugging fast because there is no compilation step included in Python development, and the edit-test-debug cycle is very fast.
Python History
Python was invented by Guido van Rossum in 1991 at CWI in Netherland. The idea of Python programming language has taken from the ABC programming language or we can say that ABC is a predecessor of Python language.
There is also a fact behind the choosing name Python. Guido van Rossum was a fan of the popular BBC comedy show of that time, "Monty Python's Flying Circus". So he decided to pick the name Python for his newly created programming language.
Python has a vast community across the world and releases its version within a short period.
##Why learn Python? Python provides many useful features to the programmer. These features make it the most popular and widely used language.
listed below are some reasons to learn python:
Easy to use and Learn
Expressive Language
Interpreted Language
Object-Oriented Language
Open Source Language
Extensible
Learn Standard Library
GUI Programming Support
Integrated
Embeddable
Dynamic Memory Allocation
Wide Range of Libraries and Frameworks
What can we use python for:
check out the list
- Data Science
- Data Mining
- Desktop Applications
- Console-based Applications
- Mobile Applications
- Software Development
- Artificial Intelligence
- Web Applications
- Enterprise Applications
- 3D CAD Applications
- Machine Learning
- Computer Vision or Image Processing Applications.
- Speech Recognition
The list above are a few of the things you can do with python, there are tons of areas you can apply your python skills to.
Python Syntax
There is no use of curly braces or semicolons in the Python programming language. It is an English-like language. But Python uses the indentation to define a block of code. Indentation is nothing but adding whitespace before the statement when it is needed. For example -
//javascript code
const a;
a = 2;
const b;
b = 3;
const c;
c = a + b;
Above is an example of javascript code. You can see how there is some verbosity in it. first, we declare the variable before assigning the code. Now let's look at similar code in python.
#python code
a = 2
b = 3
c = a + b
Look our code is easier to read, no semi-colon and no verbosity, just straightforward. That is why python is easy and fun to learn.
let us declare a function in both language so that you will see a more excellent reason to learn python why python is best for beginners learning how to program.
//function in javascript
const addTwoNumbers = function(a, b){
console.log(a+b)
}
// or
function addTwoNumbers(a,b){
console.log(a+b)
}
//or
const addTwoNumbers = (a, b) => {
console.log(a+b)
}
Now let's look at a function in python
#function in python
def add_two_numbers(a, b):
print(a+b)
That is all for this function. No drama, just straightforward.
Python Popular Frameworks and Libraries
Python has a wide range of libraries and frameworks widely used in various fields such as machine learning, artificial intelligence, web applications, etc. We define some popular frameworks and libraries of Python as follows.
- Web development (Server-side) - Django Flask, Pyramid, CherryPy, FastAPI, Bottle, etc
- GUIs based applications - Tk, PyGTK, PyQt, PyJs, etc.
- Machine Learning - TensorFlow, PyTorch, Scikit-Learn, Matplotlib, Scipy, etc.
- Mathematics - Numpy, Pandas, etc. Python has a huge application, it really depends on what you want.
Let's Look At Some Core Python Code.
Python print() Function
The print() function displays the given object to the standard output device (screen) or to the text stream file.
Unlike the other programming languages, the Python print() function is the most unique and versatile function.
The syntax of the print() function is given below.
#python print function
print("Hello World! ")
#let's look more into the print function
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Let's explain its parameters one by one.
- objects - An object is nothing but a statement that is to be printed. The * sign represents that there can be multiple statements.
- sep - The sep parameter separates the print values. Default values is ' '.
- end - The end is printed at last in the statement.
- file - It must be an object with a write(string) method.
- flush - The stream or file is forcibly flushed if it is true. By default, its value is false.
Let's look at example
print("My name is Dozie.") #replace your name with my name
name = "Dozie"
# Two objects are passed in print() function
print("name =", name)
# the values surrounded in double quote will not change, in later chapter we will dive deep and understand why it behaves that way
#we are now declaring a new variable and assigning the value of a to it
second_name = name
# Three objects are passed in print function
print('name =', name, '= second_name')
Now let's see the output of this code
Output
#first code output
print("name =", name)
#output: name = Dozie
#second code output
second_name = name
print('name =', name, '= second_name')
#output: name = Dozie = second_name
#remember: when you wrap a value in single or double quote,
#it will be printed exactly the way it was written, except for few exception where we format the string.