0% found this document useful (0 votes)
31 views

Python Programming Basics - Part 1

Uploaded by

santhosh280705
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Python Programming Basics - Part 1

Uploaded by

santhosh280705
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CHAPTER 1

PYTHON BASICS
Page 1 of 13

PYTHON BASICS

Overview of Python:
Python is a general purpose , interpreted , high-level programming language with
dynamic semantics. It was created by Guido Van Rossum in 1991 and further developed by
python software foundation. It allows to express concepts in fewer lines of code.
Who uses python:
Python is applied in many real revenue generating products by many real companies,
✓ Google:
For system building, log analysis, report generation,etc.
✓ Dropbox:
Allows for efficient file management.
✓ Youtube:
Which serves frontend & API
✓ NASA:
Uses python for data analysis and scientific calculations
✓ Raspberry Pi:
Used to build projects.Eg: blink lights, read sensors,etc.

History of Python:
Python is an interpreted , object oriented , high-level programming level
programming language with dynamic semantics. It was created by Guido Van Rossum in
1991 and further developed by python software foundation. It allows to express concepts in
fewer lines of code.

Founder of Python:
Guido Van Rossum , The founder of Python , was born and raised in Netherlands
with background of mathematics and computer science. He ultimately created one of the
most widely used programming language in the world called Python. So he is known as
father of Python . He developed the language with aim of making programming more
accessible and enjoyable for a wider audience.
Birth of Python:
In the late 1980s , the working on python was started. Guido Van Rossum began
doing its application-based work in December 1989 at Centrum Wiskunde and Informatica
(CWI) , situated in Netherlands.

CHAPTER 1 | PYTHON BASICS


Page 2 of 13

The programming language python is said to have succeeded is ABC


programming language , which of had interfacing with amoeba operating system and feature
of exception handling.

He had already helped to create ABC earlier and had some issues with ABC but
liked most of the features. He had taken the syntax of ABC, and some of its good features. It
came with a lot of complaints too, so he fixed those issues completely and created a good
scripting language. The inspiration for the name of BBC’s TV Show – ‘Monty Python’s Flying
Circus’ and also he wanted a short, unique and mysterious name and hence he named it as
Python!
Python’s First release:
After few years of development, the language was finally released in 1991. When it
was released, it used a lot fewer codes to express the concepts, when compared to Java,
C++ & C. Its design philosophy was quite good too. Its main objective is to provide code
readability and advanced developer productivity. It had more capability to provide classes
with inheritance, several core data types, exception handling and functions.
Python is a programming as well as a scripting language. This language has various
purposes such as developing, scripting, generation, and software testing. Due to its elegance
and simplicity, top technology organizations like Dropbox, Google, Quora, Mozilla, IBM, Cisco
,etc.,have implemented Python.

Origin features:
• Easy to code and maintain :
It is simple which is easy to learn and code , so it is developer-friendly . It has simple
structure, and a clearly defined syntax.

• Open source and free:


Anyone can download it, use it, and share it. It is free of cost.

• Object-oriented:
It supports object-oriented programming language features .
Eg: the concept of object and classes, encapsulation, inheritance, etc.

• Supports GUI programming:


Python has support for creating various GUI applications
. Eg: modules like PyQt5, PyQt4, wxPython, or Tk are used to make graphical user
interfaces.

• Embedded:
allows for execution of Python code inside the InterSystems IRIS process context.

CHAPTER 1 | PYTHON BASICS


Page 3 of 13

• Extensible in nature:
Means that we can use python code in other languages.

• Portable and Platform independent:


We can run the python code in any environment like windows, Linux, mac, etc without
changing it.

• Integrated Language:
We can easily integrate it with other languages such as C, C++, etc.

• Interpreted Language:
It uses an interpreter for converting the source code into machine code. This execute the
python code line by line.

• Huge Standard Library:


There are a very large number of libraries in python. These libraries contain predefined
modules and functions for certain tasks. library is portable and cross-platform compatible.
Eg: numpy, matplotlib, pandas, etc.

• Dynamically Typed:
Means that we do not have to define the type of the variable.

• Scalable:
It provides good support for large programs.

Downloading & installing python:[ Refer example window pictures]*:


➢ Step 1: Visit the link https://www.python.org to download the latest
release of Python

➢ Step 2: Select the Python's version to download : Click on the


download button to download the exe file of Python.

CHAPTER 1 | PYTHON BASICS


Page 4 of 13

➢ Step 3: Once you have downloaded the installer, open the .exe file, such as
python-3.10.11-amd64.exe, by double-clicking it to launch the Python installer.

➢ Step 4: Choose the option to Install the launcher for all users by checking the
corresponding checkbox, so that all users of the computer can access the
Python launcher application

➢ Step 5: On clicking the Install Now, The installation process starts.

➢ Step 6: The installation process will take few minutes to complete


and once the installation is successful, the following screen is
displayed i.e.,Setup was successful

➢ Step 7: Verify Python is installed on Windows: To ensure if Python


is succesfully installed on your system. Follow the given steps −
o Open the command prompt.
o Type ‘python’ and press enter.
o The version of the python which you have
installed will be displayed if the python is
successfully installed on your windows.

CHAPTER 1 | PYTHON BASICS


Page 5 of 13

Running Python:
Different ways to run Python Script or code through :

▪ The Python interactive mode


▪ Using the Python command line
▪ Run on IDLE
▪ Run On IDE (PyCharm)

I. Python interactive mode:

This is the most frequently used way to run a Python code. Here basically
we do the following:

1. Open command prompt / terminal in your system


2. Enter the command - python or python3 (based on python version installed
in your system)
3. If we see these : >>> then, we are into our python prompt. It will look
something like this:

C:\Users\sans>python
Python 3.12.1 (tags/v3.9.2:1a79785, dec 19 2023, 13:44:55) [MSC v.1928
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

4. Now we can start writing our code here.

Example :

>>> print("Hello World!")

Hello World!

Pros:

Best for testing every single line of code written.


Each line of code is evaluated and executed immediately as soon as we
hit ↵ Enter .
Great deveopment tool for experimentation of Python code on the way.

CHAPTER 1 | PYTHON BASICS


Page 6 of 13

Cons:

The code is gone as soon as we close the terminal(or the interactive session)
Not user friendly way to write long code.

II. Using the Python Command Line:


• Write your Python code into any text editor.
• Save it with the extension .py into a suitable directory

# Save it with any suitable file name(suppose hello.py)

print("Hello World!!")

• Open the terminal or command prompt.


• Type python/python3 (based on installation) followed by the file name.py--

python YourFileName.py

Example 1:

Saved with hello.py

print("Hello World!!")

OUTPUT:

C:\Users\deepa>python hello.py

Hello World!!

III. Run Python on IDLE:

Python installation comes with an Integrated Development and Learning


Environment, which is popularly known as IDLE

Steps to run a python program on IDLE:

o Open the Python IDLE


o The shell is the default mode of operation for Python IDLE. So, the first
thing you will see is the Python Shell –

CHAPTER 1 | PYTHON BASICS


Page 7 of 13

o To run a Python script you can go to File -> New File

o Now, write your code and save the file –

o Once saved, you can run your code from Run -> Run Module Or simply by pressing F5 --

Output:

CHAPTER 1 | PYTHON BASICS


Page 8 of 13

IV. Run Python On IDE (PyCharm):


o In the Project tool window, select the project root, right-click it, and select File -> New ->
Python File

o Then you will see a prompt, select the option Python File from the menu, and then type the
new filename.

o Write your code in the Python file you have just created.

o To run this file, Right click on the file name -> Run filename

CHAPTER 1 | PYTHON BASICS

You might also like