[Go to site: main page, start]

0% found this document useful (0 votes)
7 views4 pages

Chapter5 Python Notes

Chapter 5 provides an overview of Python, a high-level programming language created by Guido Van Rossum in 1991, highlighting its advantages such as ease of use and cross-platform capabilities, as well as disadvantages like slower performance compared to other languages. It details how to work in Python using different modes, including Interactive Mode and Script Mode, and introduces the Anaconda distribution with tools like Jupyter Notebook and Spyder IDE. The chapter concludes with a simple example of a Python script and key terms related to Python programming.

Uploaded by

u5021628
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Chapter5 Python Notes

Chapter 5 provides an overview of Python, a high-level programming language created by Guido Van Rossum in 1991, highlighting its advantages such as ease of use and cross-platform capabilities, as well as disadvantages like slower performance compared to other languages. It details how to work in Python using different modes, including Interactive Mode and Script Mode, and introduces the Anaconda distribution with tools like Jupyter Notebook and Spyder IDE. The chapter concludes with a simple example of a Python script and key terms related to Python programming.

Uploaded by

u5021628
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 5: Getting Started with Python

Computer Science Notes — Quick Revision

5.1 Introduction
Python was developed by Guido Van Rossum in February 1991. It is based on / influenced by:
• ABC language — a teaching language created as a replacement for BASIC
• Modula-3
Python is an easy-to-learn, powerful, object-oriented, high-level programming language.
NOTE: Python was named after the famous BBC comedy show Monty Python's Flying Circus.

5.2 Python — Pluses (Advantages)

# Plus Description

1 Easy to Use Simple, human-friendly syntax

2 Expressive Language Does more with fewer lines of code

3 Interpreted Language Commands executed one-by-one

4 Its Completeness Supports wide range of tasks

5 Cross-platform Runs on Windows, Mac, Linux

6 Free and Open Source Free to download and use

7 Variety of Usage Web, AI, data science, automation etc.

5.3 Python — Some Minuses (Disadvantages)


Although very powerful, Python is not a Perfect Programming Language.

Minus Explanation

Not the Fastest Language Slower than C, Java, Perl

Lesser Libraries Fewer libraries than C, Java, Perl

Not Strong on Type-binding Loosely typed — may cause runtime errors

Not Easily Convertible Hard to convert to other languages

5.4 Working in Python


To start working in Python, you need to install it. The default installation from [Link] is called
CPython installation. It comes with:
• Python interpreter
• Python IDLE (Python GUI)
• Pip (package installer)
Anaconda Python Distribution — a highly recommended distribution that includes NumPy, SciPy, Panda,
PyCharm IDE, Spyder IDE etc. Anaconda is also available as part of this.
Two Modes of Working in Python

Mode Description Key Feature

Interactive Mode Type one command → get output instantly


Best for testing code
(Immediate Mode) Prompt: >>>

Write all commands in a file → run together


Script Mode Best for full programs
File extension: .py

NOTE: Interactive mode proves very useful for testing code — type commands one by one and get results or
errors one by one.

5.4.1 Working in Python IDLE (Interactive Mode)


Steps to open Python IDLE:
(i) Start → All Programs → Python 3.6.x → IDLE (Python GUI)
(ii) Python Shell opens — shows prompt >>>
(iii) Type commands at >>> and Python gives results immediately
Example: >>> 2 + 5 → Output: 7

5.4.1B Working in Script Mode (Python IDLE)


Steps to create and run a script:
(i) File → New in IDLE Python Shell
(ii) A new untitled window opens — type your code here
(iii) File → Save → give .py extension (e.g., [Link])
(iv) Run → Run Module (or press F5) to execute
NOTE: print() can display as well as print values. In script mode, print() is preferably used to print results.

5.4.2 Working in Anaconda Python Distribution


Anaconda comes with many preloaded packages and libraries. Key IDEs included:
• Jupyter Notebook — web-based, interactive computing environment
• Spyder IDE — powerful Python IDE with advanced editing, interactive testing, debugging, introspection
features

5.4.2A Working in Jupyter Notebook


Steps:
1. Launch Anaconda Navigator
2. Click on Launch below jupyter notebook tile
3. Jupyter launches in the web browser — shows notebook dashboard
4. Click New → Python 3 to create a new notebook
5. Type code in Code cell → click Run to execute
To run a script: Write multiple Python commands in a code cell, give it a name, then Run.
To create a new notebook: File → New notebook

5.4.2B Working in Spyder IDE


To launch Spyder:
(i) Anaconda Navigator → Click Spyder tile
(ii) Or: Start → Programs → Anaconda → Spyder
Spyder Interface has two key areas:
• Editor pane — write/create scripts here
• IPython Console — for interactive mode; also shows output of scripts
NOTE: The IPython console shows In[n] prompts and often shows output with Out() lines.

Interactive Mode in Spyder:


Type command(s) in IPython console pane → result shown below command
Example: print("Hello") → hello
Script Mode in Spyder:
• New script: File → New File (Ctrl+N)
• Save: File → Save or File → Save As (Ctrl+S)
• Scripts saved with .py extension
• Run: Run icon on toolbar, or Run → Run, or press F5
• Output shown in IPython console
NOTE: Click in IPython console before running your script to have cursor in console.

5.4.3 Writing and Compiling Python on Linux (Command Line)


Steps:
(i) Write program in a text editor (e.g., Sublime Text, nano, vim, emacs)
(ii) Save with .py extension (e.g., [Link])
(iii) Compile and run via command prompt with appropriate command
Using Sublime Text editor steps:
(i) Open Sublime Text
(ii) File → New → write code
(iii) Write the code: print("Hello World")
(iv) Save: Ctrl+S → give .py extension → name file [Link]
Compiling & Running via Terminal (Linux):
(i) Open terminal: Ctrl+Alt+T
(ii) Go to folder: cd Desktop
(iii) Run: python [Link]

5.5 Understanding First Program / Script


Our first program:
#My First Program
print("Hello World!")

Analysing the Script:


# symbol → Comment in Python
Any line beginning with # is a comment. Python completely ignores these lines — for the programmer's
information only.
print() Function / Statement
Used to print or display output on the screen.
Syntax: print(<objects to be printed>)
Examples:

Statement Output
print("Hello World!") Hello World!

print('My name is Misha') My name is Misha

print("The Golden Ratio") The Golden Ratio

print("has same letters as") has same letters as

print('The God Relation') The God Relation

Important Rules for Strings in print():


• Strings can be enclosed in double quotes "..." or single quotes '...'
• Opening and closing quotation marks must be of the same type
• ERROR if opening and closing marks do not match (e.g., print("hello') → Error)
• You cannot have a string like 'Hey there" — mismatched quotes cause errors

Key Terms / Keywords Quick Reference

Term / Symbol Meaning

Guido Van Rossum Creator of Python (1991)

CPython Default Python installation from [Link]

Anaconda Python distribution with pre-loaded libraries

IDLE Integrated Development and Learning Environment (Python's built-in IDE)

>>> (prompt) Python interactive mode prompt

Interactive Mode One command at a time; immediate output

Script Mode Write full program → save as .py → run

.py File extension for Python program/script files

F5 Shortcut to Run Module in IDLE

print() Function to display output on screen

# (hash) Denotes a comment; Python ignores these lines

Jupyter Notebook Web-based interactive Python environment

Spyder IDE Powerful IDE included in Anaconda

IPython Console Interactive console in Spyder; shows In[n] prompts

\n Newline character

end='*' In print(), continue in same line (replaces default newline)

ASCII American Standard Code for Information Interchange

Pip Package installer for Python

Chapter 5 Complete — Computer Science with Python

You might also like