Python Basics
What is Python?
Python is a General Purpose object-oriented programming language, which means that it can model real-
world entities. It is also dynamically-typed because it carries out type-checking at runtime.
It does so to make sure that the type of construct matches what we expect it to be.
The distinctive feature of Python is that it is an interpreted language.
The Python IDLE (Integrated Development Environment) executes instructions one line at a time. This
also lets us use it as a calculator.
Why is it called Python?
Guido van Rossum named it after the comedy group Monty Python. That is why the metasyntactic
variables (those we will often use to explain code syntax) used here are ‘spam’ and ‘eggs’ instead of
‘foo’ and ‘bar’.
Python Features
Let us now see various features of Python that make it so powerful and popular:
Easy
o Python is very easy to learn and understand; any beginner can learn Python easily. When writing
code in Python, you need fewer lines of code compared to languages like Java.
Interpreted
o It is interpreted(executed) line by line. This makes it easy to test and debug.
Object-Oriented
o The Python programming language supports classes and objects and hence it is object-oriented.
Free and Open Source
o The language and its source code are available to the public for free; there is no need to buy a
costly license.
Portable
o Since Python is open-source, you can run it on Windows, Mac, Linux or any other platform.
Your programs will work without any need to change it for every machine.
GUI Programming
o You can use it to develop a GUI (Graphical User Interface). One way to do this is through
Tkinter.
Large Python Library
o Python provides you with a large standard library.
o You can use it to implement a variety of functions without the need to reinvent the wheel every
time. Just pick the code you need and continue.
Python Architecture and Working
Let’s now talk about Python architecture and its usual flow –
Parser
o It uses the source code to generate an abstract syntax tree.
1|Page
, Compiler
o It turns the abstract syntax tree into Python bytecode.
Interpreter
o It executes the code line by line in a REPL (Read-Evaluate-Print-Loop) fashion.
Python Constructs
a. Functions in Python
A function in Python is a collection of statements grouped under a name. You can use it whenever you
want to execute all those statements at a time.
You can call it wherever you want and as many times as you want in a program. A function may return a
value.
b. Classes in Python
As we discussed earlier, Python is an object-oriented language. It supports classes and objects.
A class is an abstract data type. In other words, it is a blueprint for an object of a certain kind. It holds no
values.
An object is a real-world entity and an instance of a class.
c. Modules in Python
Python module is a collection of related classes and functions.
We have modules for mathematical calculations, string manipulations, web programming, and many
more.
d. Packages in Python
Python package is a collection of related modules. You can either import a package or create your own.
Features of Python
1. Easy
When we say the word ‘easy’, we mean it in different contexts.
Easy to Code
o Python is very easy to code as compared to other popular languages like Java and C++.
o Anyone can learn Basic Python syntax in just a few hours. Thus, it is programmer-friendly.
Easy to Read
o Being a high-level language, Python code is quite like English. Looking at it, you can tell what
the code is supposed to do.
o Also, since it is dynamically-typed, it mandates indentation. This aids readability.
2. Expressive
First, let’s learn what is expressiveness. Suppose we have two languages A and B, and all programs that
can be made in A can be made in B using local transformations.
2|Page
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller toulikmaitra. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $3.49. You're not tied to anything after your purchase.