INTRODUCTION TO PYTHON
ABOUT PYTHON
Python is an interpreted, high-level, general-purpose programming
language created by GUIDO VAN ROSSUM and first released in
1991. Python’s design philosophy emphasizes code readability with
it’s notable use of significant whitespace. It’s language constructs
an object-oriented approach aim to help programmers write clear,
logical code for small and large-scale projects. Some of it’s useful
filename extensions are :-
1. .py
2. .pyi
3. .pyc
FEATURES OF PYTHON
1. EASY TO LEARN AND USE:- Python is easy to learn and use. It is developer -friendly
and high level programming language.
2. EXPRESSIVE LANGUAGE:- Python language is more expressive means that it is more
understandable and readable.
3. INTERPRETED LANGUAGE:- Python is an interpreted language i.e. interpreter executes
the code line by line at a time.
4. CROSS-PLATFORM LANGUAGE:- Python can run equally on different platforms such
as Windows, Linux, Unix and Macintosh etc.
5. FREE AND OPEN SOURCE:- Python language is freely available at official web address.
The source-code is also available. Therefore it is open source.
6. OBJECT ORIENTED LANGUAGE:- Python supports object oriented language and
concepts of classes and objects come into existence.
7. EXTENSIBLE:- It implies that other languages such as C/C++ can be used to compile
the code and thus it can be used further in our python code.
8. LARGE STANDARD LIBRARY:- Python has a large and broad library and
provides rich set of module and functions for rapid application development.
9. GUI PROGRAMMING SUPPORT:- Graphical user interfaces can be developed
using Python.
10. INTEGRATED:- It can be easily integrated with languages like C, C++,JAVA etc.
ADVANTAGES OF PYTHON
1. EASY TO READ, LEARN AND WRITE:- Python is a high-level programming
language that has English-like syntax.
2. IMPROVED PRODUCTIVITY :- Python is a very productive language. Due to
the simplicity of python, developers can focus on solving the problem.
3. INTERPRETED LANGUAGE:- Python is an interpreted language which means
that Python directly executes the code line by line. This makes debugging
easier.
4. DYNAMICALLY TYPED:- Python doesn’t know the type of variable until we run
the code. It automatically assign the data type during execution.
5. FREE AND OPEN SOURCE:- Python comes under the OSI approved open-
source license. This makes it free to use and distribute.
6. VAST LIBRARIES SUPPORT:- The standard library of Python is huge, you can
find almost all the functions needed for your task.
7. PORTABILITY:- You only write once and run it anywhere. However, you should
be careful not to include any system-dependent features.
DISADVANTAGES OF PYTHON
1. SLOW SPEED:- We discussed that Python is an interpreted language and
dynamically typed language. The line by line execution of code often leads to slow
execution.
2. NOT MEMORY EFFICIENT:- To provide simplicity to the developers, the Python
programming language uses a large amount of memory.
3. WEAK IN MOBILE COMPUTING:- Python is generally used in server-side
programming. We don’t get to see Python on the client side or mobile applications.
4. DATABASE ACCESS:- The Python’s database access layer is primitive and
underdeveloped in comparison to the popular technologies like JDBC and ODBC.
5. RUNTIME ERRORS:- A variable containing integer number may hold a string in
the future, which can lead to Runtime Errors.
POPULAR IDE’S OF PYTHON
IDLE
1. When you install Python, IDLE is also installed by default. This makes it easy to
get started in Python. Its major features include the Python shell
window(interactive interpreter), auto-completion, syntax highlighting, smart
indentation, and a basic integrated debugger.
2. IDLE is a decent IDE for learning as it's lightweight and simple to use. However,
it's not for optimum for larger projects.
SPYDER
Spyder is an open-source IDE usually used for scientific development.
The easiest way to get up and running with Spyder is by installing Anaconda
distribution. If you don't know, Anaconda is a popular distribution for data science
and machine learning. The Anaconda distribution includes hundreds of packages
including NumPy, Pandas, and so on.
Spyder has some great features such as autocompletion, debugging and iPython
shell.
MODES OF PYTHON
1. INTERACTIVE MODE.
2. SCRIPT MODE.
PYTHON INTERACTIVE MODE
1. Interactive mode provides us with a quick way of running blocks or a
single line of Python code. The code executes via the Python shell, which
comes with Python installation. Interactive mode is handy when you just
want to execute basic Python commands or you are new to Python
programming and just want to get your hands dirty with this beautiful
language.
2. To access the Python shell, open the terminal of your operating system
and then type "python". Press the enter key and the Python shell will
appear. This is the same Python executable you use to execute scripts,
which comes installed by default on Mac and Unix-based operating
systems.
PYTHON SCRIPT MODE
1. If you need to write a long piece of Python code or your Python script spans
multiple files, interactive mode is not recommended. Script mode is the way to go
in such cases. In script mode, You write your code in a text file then save it with
a .py extension which stands for "Python".
2. If you are in the standard Python shell, you can click "File" then choose "New" or
simply hit "Ctrl + N" on your keyboard to open a blank script in which you can write
your code. You can then press "Ctrl + S" to save it.
3. After writing your code, you can run it by clicking "Run" then "Run Module" or
simply press F5.
USAGE OF PRINT()FUNCTION
1. The print function in Python is a function that outputs to
your console window whatever you say you want to print
out. At first blush, it might appear that the print function is
rather useless for programming, but it is actually one of the
most widely used functions in all of python. The reason for
this is that it makes for a great debugging tool.
2. "Debugging" is the term given to the act of finding,
removing, and fixing errors and mistakes within code.
3. If something isn't acting right, you can use the print
function to print out what is happening in the program.
Many times, you expect a certain variable to be one thing,
but you cannot see what the program sees. If you print out
the variable, you might see that what you thought was, was
not.
EXAMPLES OF PRINT( ) FUNCTION