0% found this document useful (0 votes)
47 views8 pages

Programming in Python

The document provides an introduction to the Python programming language. It discusses what programming languages and Python are, and covers various Python topics like data types, variables, operators, control flow, functions, modules and packages. It also explains key features of Python like being an interpreted, object-oriented, cross-platform and having a large standard library.

Uploaded by

sanjiblifestyle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
47 views8 pages

Programming in Python

The document provides an introduction to the Python programming language. It discusses what programming languages and Python are, and covers various Python topics like data types, variables, operators, control flow, functions, modules and packages. It also explains key features of Python like being an interpreted, object-oriented, cross-platform and having a large standard library.

Uploaded by

sanjiblifestyle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

Python Programming

Introduction to Python:
What does it mean by language?
Human beings use languages for communication. We use the languages like
English, Hindi, French, Bengali. These are the natural languages. These are called
as natural languages. So, we use these languages for communication.
Likewise, machines also have their languages. This is our computer system
that is also having its own language. And that language we call it as machine
language. And this machine works in number system that is binary number system
that is in the form of zeros and ones only.
What is programming?
Programming means a step-by-step procedure for solving any problem.
So a language that is used for writing the procedures which machines can
understand and execute them and machines do the processing so that languages
are nothing but programming languages.
Types of Programming Languages
 Low-Level Language
 Machine Language
i) The machine language that is in the form of only zeros and ones.
ii) Humans cannot understand this language that is zeros and ones
easily.
 Assembly Language
 High-Level Language
o General Purpose
o Special Purpose
o Scripting
Then later people thought that let us use English like languages for writing
the programs such languages are called as high-level languages.
We write the programs using C language, then we compile it and the
compiler will convert this C language program into machine language
code.
 General Purpose
The language can be used for writing various types of programs like
desktop application, web application, cloud application, enterprise
application, mobile application, telecommunication application system
programming so on.
But a language which is used for writing any type of application is
called as general-purpose language.
he languages as C, C++, Java, C#, python. These are all high-level
languages which are useful for various purpose of programming
 Special Purpose
There are some special purpose languages, like there are some
languages only for web development, there are some languages that are
only for mobile development, like Swift is the language or a Android
language. There are some languages only for gaming purpose, so such
languages are called as special purpose languages.
Example: JS, Android
 Scripting
They are very easy to write means they will not have very strict rules of
programming. It is easy for the programmer to write down the code, so
those are usually called as scripting languages.
Python is a general-purpose language, but it is more like scripting
language, so it's easy to learn and develop the application.

High-Level Language
 Compiler Based (C, C++)
 Interpreter Based (JS, PHP)
 Hybrid (Java, C#, Python, .Net)
The high-level languages are either compiler based or interpreter based or hybrid.
We write the programs using high level language. Machine cannot understand that
language, so this high-level language program code should be translated into
machine language code.
Who does the translation?
So, translation is done either by compiler or interpreter. So, it's done either by
compiler or interpreter. There are two methods of translation.
So, some programming languages uses only compiler some programming
languages, uses only interpreter, and some uses both. Some are hybrid languages,
which uses both compiler and interpreter.
Compiler VS Interpreter
Compiler:
i) Compiler takes the complete source program and generates complete
machine code program. It takes a file and it gives a new file that contains
a complete machine code.
ii) If there are no errors in your program, then only this translation is done
into machine code.
iii) Only one time translation is done.
Interpreter:
If these are the lines of JavaScript code, the interpreter will translate one line into
machine code. It will generate the machine code just for one line and also get it
executed at that time. Only then second line translate into machine code, get it
executed next line, convert it into machine code executed each line it will take
and convert into machine code and also it will get executed. So this is how
interpreter works.
Difference between Compiler and Interpreter
i) See, the compiler was not executing it. Compiler was giving complete
machine code. You execute whenever you want, but interpreter will directly
execute it on the machine.
ii) Interpreter will convert each line into machine code and getting executed and
separate file is not generated but compiler will generate two separate files.
iii) Compiler based languages are faster than interpreter-based languages because
in interpreter-based languages, every time translation is done, program is
translated into machine code and executed. So, we say it is done line by line.
Sometime the entire code is converted also, but always the translation is done.
iv) Interpreter languages are easier to write and run because they run inside the
runtime environment, which is more comfortable for the programmer to
develop such programs by taking the support of runtime environment.
How a Python Program Runs?
It will compile this source code into intermediate code called bytecode. it converts into
bytecode and it generates one hidden file. Actually, it's cannot be seen. So, the file name is
program (.pyc) so it was (.pyc) file but now it is compiled file.
When the compilation is done. Compiler will check if there are any errors in the
program. If there are no errors, then it will convert into machine code. Interpreter will not check
for the errors because already the bytecode is error free. So, what it has to do just it has to
translate this bytecode into machine code that is machine language. So, Python's interpreter
will translate bytecode into machine code and execute. When you run a program, it gets
compiled and then interpreted and executed by Python Virtual Machine that is PVM.
Python Features

Python provides many useful features which make it popular and valuable from
the other programming languages. It supports object-oriented programming,
procedural programming approaches and provides dynamic memory allocation.
We have listed below a few essential features.

1) Easy to Learn and Use

Python is easy to learn as compared to other programming languages. Its syntax


is straightforward and much the same as the English language. There is no use of
the semicolon or curly-bracket, the indentation defines the code block. It is the
recommended programming language for beginners.

2) Expressive Language

Python can perform complex tasks using a few lines of code. A simple example,
the hello world program you simply type print("Hello World"). It will take only
one line to execute, while Java or C takes multiple lines.

3) Interpreted Language

Python is an interpreted language; it means the Python program is executed one


line at a time. The advantage of being interpreted language, it makes debugging
easy and portable.

4) Cross-platform Language

Python can run equally on different platforms such as Windows, Linux, UNIX,
and Macintosh, etc. So, we can say that Python is a portable language. It enables
programmers to develop the software for several competing platforms by writing
a program only once.

5) Free and Open Source


Python is freely available for everyone. It is freely available on its official
website www.python.org. It has a large community across the world that is
dedicatedly working towards make new python modules and functions. Anyone
can contribute to the Python community. The open-source means, "Anyone can
download its source code without paying any penny."

6) Object-Oriented Language

Python supports object-oriented language and concepts of classes and objects


come into existence. It supports inheritance, polymorphism, and encapsulation,
etc. The object-oriented procedure helps to programmer to write reusable code
and develop applications in less code.

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. It converts the program into
byte code, and any platform can use that byte code.

8) Large Standard Library

It provides a vast range of libraries for the various fields such as machine learning,
web developer, and also for the scripting. There are various machine learning
libraries, such as Tensor flow, Pandas, Numpy, Keras, and Pytorch, etc. Django,
flask, pyramids are the popular framework for Python web development.

9) GUI Programming Support

Graphical User Interface is used for the developing Desktop application. PyQT5,
Tkinter, Kivy are the libraries which are used for developing the web application.

10) Integrated

It can be easily integrated with languages like C, C++, and JAVA, etc. Python
runs code line by line like C, C++ Java. It makes easy to debug the code.

11. Embeddable

The code of the other programming language can use in the Python source code.
We can use Python source code in another programming language as well. It can
embed other language into our code.

12. Dynamic Memory Allocation


In Python, we don't need to specify the data-type of the variable. When we assign
some value to the variable, it automatically allocates the memory to the variable
at run time. Suppose we are assigned integer value 15 to x, then we don't need to
write int x = 15. Just write x = 15.
Python Interpreter, Using Python as calculator, Python shell, Indentation. Atoms,
Identifiers and keywords, Literals, Strings, Operators (Arithmetic operator,
Relational operator, Logical or Boolean operator, Assignment, Operator, Ternary
operator, Bit wise operator, Increment or Decrement operator)
Creating Python Programs:
Input and Output Statements, Control statements (Branching, Looping,
Conditional Statement, exit function, Difference between break, continue and
pass.), Defining Functions, default arguments, Errors and Exceptions.
Iteration and Recursion: Conditional execution, Alternative execution, Nested
conditionals, The return statement, Recursion, Stack diagrams for recursive
functions, Multiple assignment, The while statement, Tables, Two-dimensional
tables Strings and Lists: String as a compound data type, Length, Traversal and
the for loop, String slices, String comparison, A find function, Looping and
counting, List values, Accessing elements, List length, List membership, Lists
and for loops, List operations, List deletion. Cloning lists, Nested lists
Object Oriented Programming: Introduction to Classes, Objects and Methods,
Standard Libraries.
Data Structures: Arrays, list, set, stacks and queues.
Searching and Sorting: Linear and Binary Search, Bubble, Selection and
Insertion sorting.

You might also like