Python is a popular programming language.
It was created by Guido van
Rossum, and released in 1991.
It is used for:
● web development (server-side),
● software development,
● system scripting.
Reasons for popularity:
● Python can be used on a server to create web applications.
● Python can be used alongside software to create workflows.
● Python can connect to database systems. It can also read and modify
files.
● Python can be used to handle big data and perform complex
mathematics.
● Python can be used for rapid prototyping, or for production-ready
software development.
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
● Python runs on an interpreter system, meaning that code can be executed
as soon as it is written. This means that prototyping can be very quick.
● Python can be treated in a procedural way, an object-oriented way or a
functional way.
Features of Python:
1. Easy to Learn
One of the most significant features of Python is that it is very easy to learn.
The language has a simple syntax and structure that makes it easy for
beginners to learn and start coding quickly. Python code is also easy to read
and understand, which makes it an excellent choice for collaborative
projects.
2. Easy to Code
Python is a high-level language that requires minimal coding efforts. It has a
rich set of libraries and modules that simplify the coding process, making it
possible to build complex applications quickly.
3. Interpreted Language
One of the important features of Python is that it is an interpreted
language, which means that the code is executed line by line. This makes
the debugging process easier, as errors can be caught and fixed in real time.
4. Free and Open Source
Python is a free and open-source language, which means that anyone can
use it, modify it, and distribute it without any restrictions. This makes it an
ideal choice for developers and programmers who want to build software
applications without incurring high costs.
5. Object-Oriented Language
Python is an object-oriented language, which means that it supports
concepts such as encapsulation, inheritance, and polymorphism. This makes
it easy to write code that is reusable and easy to maintain.
6. Cross-Platform Language
Python is a cross-platform language, which means that it can run on
different operating systems such as Windows, Linux, and macOS. This
makes it easy to develop software applications that can run on multiple
platforms.
7. High-Level Language
Python is a high-level language, which means that it is closer to human
language than machine language. This makes it easy to write code that is
easy to understand and maintain.
8. Databases Support
Python has built-in support for databases such as MySQL, PostgreSQL, and
SQLite. This makes it easy to build applications that require data storage and
retrieval.
9. GUI Programming Support
Python has a wide range of GUI libraries such as Tkinter, PyQt, and
wxPython, which makes it easy to develop graphical user interfaces for
applications.
10. Large Standard Library
Python has a large standard library that includes modules for different tasks
such as web development, networking, data processing, and more. This
makes it easy to develop applications without having to write custom code.
Installing Python
Python comments:
Comments in Python are the lines in the code that are ignored by the
interpreter during the execution of the program. Comments enhance the
readability of the code and help the programmers to understand the code
very carefully.
There are three types of comments in Python:
● Single line Comments
● Multiline Comments
Example for single line comments:
# Print “GeeksforGeeks !” to console
print("GeeksforGeeks")
Output:
GeeksforGeeks
Example for Multiline comments:
# Python program to demonstrate
# multiline comments
print("Multiline comments")
Output:
Multiline comments
Conversions
1) Mixed mode operations:
● Operation between int and float will yield float.
● Operation between int and complex will yield complex.
● Operation between float and complex will be complex.
2) We can convert one numeric type to another using built-in functions int(),
float(),complex() and bool().
3) Type conversions:
● int(float/numeric string) {from float or numeric string to integer}
● int(numeric string, base) {from numeric string to int in base}
● float(int/numeric string) {from int or numeric string to float}
● float(int) {from int to float}
● str(int/float) {converts to string}
● int() removes the decimal portion from the quotient, so always
rounds towards zero. {Example: (1) int(3.33) yields 3, (2) int(-3.33)
yields -3}
Built-in functions:
Python has many built-in functions that are always available in any part of the
program.
● print() functions that we have been using to send output to screen is a
built-in function.
● abs(x) {Returns the absolute value of a number}
● pow() {Returns the value of x to the power of y}
● min(x1,x2,x3,...) {Returns the smallest item in an iterable}
● oct() {Converts a number into an octal}
● max() {Returns the largest item in an iterable}
● input() {Allowing user input}
● hex() {Converts a number into a hexadecimal value}
● float() {Returns a floating point number}
● round() {Rounds a numbers}
● str() {Returns a string object}
● type() {Returns the type of an object}
Built-in Modules:
Apart from built-in functions, Python provides many built-in modules. Each
module contains many functions.
For performing sophisticated mathematical operations we can use the functions
present in built-in modules
● math - many useful mathematics functions.
● cmath -functions for performing operations on complex numbers.
● random - functions related to random number generations.
● decimal- functions for performing precise arithmetic operations.
● Mathematical functions in math module:
1) pi, e {Values of constants pi and e}
2) sqrt(x) {square root of x}
3) factorial(x) {x!}
4) fabs(x) {absolute value of float x}
5) exp(x) {e raised to x}
6) ceil(x) {smallest integer >=x}
7) floor(x) {largest integer <=x}