Python Shell Programming

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

PYTHON SHELL PROGRAMMING:

ScriptRunMode/Dev. Mode
You can store code in a file and use the interpreter to execute the contents of the file, which
is called a script. Python scripts have names that end with .py Extension.

Example:
1. Goto IDLE, Select File and click on New or Ctrl+N (to Open New Window)
2. Enter required python statements or commands

print("Welcome to Script MODE")


print('Welcome to Dev MODE')
print("""It is a PYTHON Shelll""")
print('''Good Bye...!!''')
print(12345)

3. Save with .py Extension @ desired location


4. Hit the key F5 or Goto run menu click Run
5. The out put displayed in readonly format on the IDLE
6. Do required modifications in the saved file and re-run..!!

PYTHON File Other Extensions:


.py ==> Python File (Regular Scripts)
.py3 ==> (rarely used) Python3 script
.pyc==> This is the compiled bytecode/compiled scripts(Bytecode)
.pyd ==> This is basically a windows dll file
.pyo ==> This is optimized pyc file
.pyw==Python script for Windows
.pyz ==> Python script archive (Compressed or Zip formated)

SETTING PYTHON PATH IN Windows:


Right click on My Computer ==>Properties ==> Advanced System Settings ==>Environment
Variable ==>New
In Variable name write path and in Variable value.
>>> import os
>>> os.getcwd()
Displays PYTHON Installed Path, copy path without quotes ==> Click Ok ==>Ok.

Clear screen in Windows:


There is no python builtin command for IDLE to clear the screen. We can perform through
customized or userdefined commands..!!

>>> print("\n"*20)#displaying blank lines


>>> clear="\n"*20#Assign blank lines
>>> print(clear)#displaying blank lines

Working with Python in Unix & Linux Environments:


Define Unix?
Unix is a family of multitasking, multiuser computer operating systems. In Unix Python
default installed, It is called standard PYTHON.

$python ==> To open PYTHON prompt


$python -v ==> To display verbose info
$python --version ==> To display Version of PYTHON
$man python ==> To display Manual Pages of PY

In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen

In Unix Python can be executed in two Run Modes:


1. Interactive Run Mode ==> Command Mode
2. Script Run Mode ==> Shell Mode or Dev Mode

Execute a Python script (Interactive Run Mode)


$ python
>>> print("Hello World!")
>>> print "Hello World"
>>> x=raw_input("Enter Any Number: ")
>>> y=raw_input("Enter Any Number: ")
>>> x+y
>>> x=input("Enter Any Number: ")
>>> y=input("Enter Any Number: ")
>>> x+y
>>> import os
>>> os.getcwd()
>>> import platform
>>> platform.python_version()
>>> import keyword
>>> keyword.kwlist

2. Script Run Mode:


It is popularly known as Development mode. You can store code in a file and use the
interpreter to execute the contents of the file, which is called a script

What is Shebang?
The term shebang refers to the "#!" located at the top of many script files that points to the
path of the associated program. It has the following alias Names:
1. She-bang 2. Hashbang
3. Pound-bang 4. Hash-pling
5. Crunchbang....etc..!!

$which command:
It is used to display the path of interpreter or compiler, installed technology in UNIX.

Syntax:
$which <interpreter/compiler name>
Example:
$which python
/usr/bin/python
/ ==> root directory
usr ==> Default Directory
bin ==> Binary Directory
python ==> Name of the interpreter
Directory ==> Collection of sub-directories and files

Editors in UNIX:
Editor is a kind of ASCII formated file. It contains ANSI standard data like Alphabets,
Numbers and Special Characters. These are text formated files. In UNIX there are different
types editors are existed.
1. QUED ==> QUick EDitor
2. FRED ==> FRiendly EDitor
3. ED ==> standard EDitor
4. EX ==> EXtended editor/Advanced Editor
5. VI ==> VIsual editor
6. VIM ==> Visually IMproved editor ..................!!

The usage of #!/usr/bin/python plays a role if the script is executable, and called without the
preceding language.

Example:
$vi MyScript.py
$ ==> Unix User Prompt/Primary Prompt
# ==> Unix/Linux Admin/Super User Prompt
Prompt ==> User Interface
vi ==> Name of the Editor
MyScript ==> Name of the file
. ==> Embedded/Period character
py ==> Extension of the file

$vi MyScript.py ==> hit the return key (Enter)


vi contains the following three modes:
1. Command Mode: In this mode we can execute only shortcut keys.
2.Insert Mode:In this mode we can write logical statements.
3. ExCommandMode: In this mode we can execute the required script(s) or logic(s).

Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")

Hit the key Esc button, to convert into command mode.


hit the key :wq (Save and Exit)

Executing PYTHON Script:


$python MyScript.py (hit the return/enter key)
Output displayed..!!

INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.

Programmers View of Interpreter


Interpreter is a software, which takes source code, reads it line by line and executes it line by
line to produce the output.

Inside INTERPRETER
In Compiled languages are, compiler converts the source code into machine code or binary
code, which is directly executed by the machine. In PYTHON compiler is using to convert the
source code(.py) into byte code.(.pyc)

What is Byte Code in PYTHON?


Byte code is easily readable by PYTHON Virtual Machine and Source code easily
understandable by programmers.
1 Low Level
2 Platform Independent
3 Efficient
4 Intermediate
5 Representation of your source code

PVM is read the byte code line by line and execute every line and produce output. In that
process PVM uses all your Library Modules.

What are PYC files?


Python automatically compiles your script to compiled code, so called byte code, before
running it.
__pycache__:
It is a folder containing Python-3 byte-code compiled and ready to be executed.

Example:
import py_compile
print(dir(py_compile))

Example:
import compileall
print(dir(compileall))

Example:
import py_compile
py_compile.compile("MyScript.py")
Steps to Work with PYTHON INSIDE:
1. Create a Folder/Directory on the Desktop ( or in AnyLocation)
2. Create a py file in that folder
3. Go to command prompt, change to current Folder/Dir location
4. python and hit the return key
5. import py_compile
6.py_compile.compile("filename.py")
7. __pycache__ folder created automatically with byte code
8. cd __pycache__
9. python file.cpython-38.pyc, to execute byte code directly without source code

PYTHON RealTime IDEs


Define IDE?
Integrated Development Environment is a software application, that provides comprehensive
facilities to computer programmers for software development.

What is PyCharm?
It is the best IDE for realtime PYTHON projects. It provides code analysis, a graphical
debugger, an integrated unit tester and supports web development with Django framework.

PyCharm Come in two editions:


1 Community Edition (Fully-Free)
2 Professional Edition (Commercial-$199)

PyCharm IDE Installation:


1 Go to https://www.jetbrains.com/pycharm/download
OR
2 https://www.jetbrains.com/pycharm/promo/anaconda/
3 Install any Edition Community or Professional
4 It is cross-platform and works on Windows, macOS, and Linux.

PyCharm IDE Features List:


1 Intelligent Coding Assistance
2 Built-in Developer Tools
3 Web Development
4 Scientific Tools

Components of Pycharm:
It has maily the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window

How to create a project:


1. Goto file menu, click on New project, Enter name of the Project PYTHON_4PM
2. Select Current window
3. Right click on the project select Python file, enter name of the file.
4. Enter required python source code as follows

Example:
print("Hello Welcome to PYCHARM")
x=input("Enter any Number: ")
print(x)
import os
print(os.getcwd())
import sys
print(sys.platform)
print(sys.path)
import platform
print(platform.python_version())
import keyword
print(keyword.kwlist)

To run the code Ctrl+Shift+F10

Creating html files:


Right click on created project, select html file, enter required file name, click on ok.

Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Naresh i Technologies</title>
</head>
<body>
<h1 style="color:red;font-family:candara;text-decoration:line-through">Welcome to PYTHON
Django Environment </h1>
<h3>It is PYTHON Web Framework..!!</h3>
<marquee>
<img src="https://www.google.co.in/images/branding/googlelogo.png" width="100px"
height="100px"/>
</marquee>
</body>
</html>

Debugging in PYCHARM:
It is the process of identifying and fixing problems in Code. The following short-cut keys are
required to debug..!!
1 Step Over (F8)
2 Step Into (F7)
3 Force Step Into (Alt+Shift+F7)
4 Step Out (Shift+F8)
5 Run to Cursor (Alt+F9)
Example:
a=int(input("Enter Any Number: "))
b=int(input("Enter Any Number: "))
c=a+b
print("The Result is: ",c)
d=a-b
print("The Result is: ",d)
e=a*b
print("The Result is: ",e)
f=a/b
print("The Result is: ",f)

What is Anaconda?
The Most Popular Python Data Science Platform.
It is a freemium open source distribution of the Python and R PLs for large-scale data
processing, predictive analytics and scientific computing.

How to Install Anaconda?


1. https://www.anaconda.com/download/
2. Click on Python 3.7 version 64-Bit Installer download
3. After successful Installation of Anaconda Platform
4. Go to MSDOS Command Prompt type spyder or jupyter notebook
5. SPYDER(Scientific PYthon Development EnviRonment)
6. JUPYteR (formerly==>iPython(JUlia, PYthon and R)

Coding Environments
Anaconda comes with two popular IDEs :

Spyder:
It is a powerful IDE for the Python language with advanced editing, interactive testing,
debugging features..!!

General features:
1. iPython=>Enhanced interactive Python interpreter
2. NumPy =>Nummerical PYthon-Linear Algebra
3. SciPy=>Scientific Python-Signal & Image Processing
4. Matplotlib=>Interactive 2D/3D plotting
5. Pandas=>For Data Analysis with Data Frames
6. Scikit-learn==> It is a Machine Learning library

Spyder Shortcut Keys


1 Press F5 to run the entire script
2 Press F9 to run selection line
3 Press Ctrl + 1 to comment / uncomment
4 Ctrl+Enter executes the current cell.
Main Components in Spyder.
1 Dashboard 2 Project Explorer
3 Editor 4 Console 5 Help

What is Anaconda Navigator?


It is a desktop GUI, that allows you to launch applications and easily manage conda
packages without using command-line commands.

Jupyter Notebook:(http://jupyter.org/)
Formerly known as the IPython Notebook. It is a server-client application that allows editing
and running notebook documents via a web browser.

Features of Jupyter Notebook:


1 Edit/Run code in the browser
2 It supports 40+ Programming Languages
3 Share notebooks: using email, Dropbox, GitHub
4 BigData Integration

Example: (Plotting Examle)


import matplotlib.pyplot as plt
x=[1,2,3,4,5,10,11,12,30,31,89]
plt.plot(x,'bo-')
plt.xlabel("Time")
plt.ylabel("Price")
plt.show()

Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.

Goto Ancondata Prompt and do the follwing:


$conda update conda
$conda install numpy
$conda help
$conda help config
$conda help info

What is pip
It is a package manager for Python programming language.

Installation
$python get-pip.py

Syntax:
pip list [options]

Upgrading pip: UNIX:


$pip install -U pip
pip Commands:
$pip list $pip help $pip help install
$pip search django $pip install pympler
$pip uninstall django $pip show django
$pip download django $pip install virtualenv
https://pip.pypa.io/en/stable/reference/

What is PyDev?
PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython
development. http://www.pydev.org/

Define RODEO?
A Native Python IDE for Data Science
https://rodeo.yhat.com/

FAQs on Pre Core PYTHON:


1. Define Scripting?
2. Types of Scripts?
3. Diff between Programming Langs and Scripting Langs
4. Why Script?
5. Features and Limitation of Scripting?
6. Why script is Smart Programming?
7. What is Paradigm?
8. Define PYTHON?
9. Any Five features of PYTHON
10. Why Python is General Purpose programming?
11. Is Python complete language?
12. How and Who developed Python?
13. Python in Realtime?
14. Any Five Python Libs?
15. IDLE stands for
16. Name of the PYTHON Prompt?
17. How to clear screen in IDLE?
18. print() detailed syntax?
19. List any 10 PYTHON Keywords
20. How to display PYTHON version?
21. Single Lone Under score
22. How to Join lines in PYTHON?
23. What are the quotes in PYTHON?
24. How to configure shorcut keys in IDLE?
25. Write Comment notation?
26. PYTHON Interpreter Architecture?
27. How PYTHON generates ByteCode?
28. Write any five PYTHON file Extensions
29 What is Shell in PYTHON?
30 Define statement, command, os?
31. define IDE?
32. Define PYCHARM?
33. How to debug py script in PYCHARM?
34. Define Anaconda, Conda and Miniconda?
35. What is Spyder?
36. Write any three features of Spyder?
37. Why Jupyter Notebook?
38. What is Conda Lib?
39. How to use PiP?
40. Write any five PiP Commands?

Type Conversion or Type Casting:


Since Python is dynamically-typed, you may want to convert a value into another type. Every
value in Python has a data type.

Python Explicit Data Type Conversion


Primitive Data Structures:
Integers Float Strings Boolean
Non-Primitive Data Structures:
Lists Tuples Sets Dictionary

List of PYTHON Functions


1 int(x [,base]) 2 bool() 3 float(x)
4 str(x) 5 list(s)6 tuple(s)
7 set(s) 8 dict(d) 9 ord(x)
10 chr(x) 11 complex(real,img)
12 eval()

int(x [,base]):
It converts a number in given base to decimal.

Syntax:
int(string, base)

Parameter :
string : consists of 1's and 0's
base : (integer value) base of the number.

Example:
print(int(123))
print(int(123.098))
print(int(123.001))

Example:
print(int("1010",2))#10
print(int("1110",2))#14
print(int("1111",2))#15
Example:
print(int("12",8))#10
print(int("123",8))#83
print(int("34",8))#28

Example:
print(int("19",16))#25
print(int("4f",16))#79
print(int("98",16))#152

NOTE:
ValueError: int() base must be >= 2 and <= 36, or 0

Example:
print(int("111",2))#7
print(int("111",3))#13
print(int("111",4))#21
print(int("111",5))#31

bool()
It converts the value into a boolean.

Syntax:
bool(value)

The following values are considered false in Python:


None
False
Zero of any numeric type. For example, 0, 0.0, 0j
Empty sequence. For example, (), [], ''.
Empty mapping. For example, {}

NOTE: All other values except these values are considered true

Example:
print(bool([])); print(bool(['a value']))
print(bool('')); print(bool('A string'))
print(bool(True)); print(bool(False))
print(bool(0)); print(bool(None))
print(bool(0.0)); print(bool(1))

float(x): To convert x to a floating-point number.

Syntax:
float(value)

Example:
a=100
print(float(a))

NOTE:
We can convert any value to float type except complex type.

str() : It is Used to convert integer into a string.

Syntax:
str(value)

Example:
a=100
print(type(a)) #<class 'int'>
print(str(a))
print(type(a)) #<class 'str'>

NOTE:
If we want to convert str type to int type, string must contain only integral value.

list() :
It is used to convert any data type to a list type.

Syntax:
list(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyList=list(MyStr)
print(type(MyList))
print(MyList)

tuple() : It is used to convert to a tuple.

Syntax:
tuple(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyTuple=tuple(MyStr)
print(type(MyTuple))
print(MyTuple)

set() :
It returns the type after converting to set

Syntax:
set(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MySet=set(MyStr)
print(type(MySet))
print(MySet)

dict() :
It is used to convert a tuple of order (key,value) into a dictionary.

Syntax:
dict(key,value)

Example:
MyTup=(('a',1),('b',2),('c',3))
print(type(MyTup))
MyDict=dict(MyTup)
print(type(MyDict))
print(MyDict)

ord() :
It is used to convert a character to integer.

Syntax:
ord('Char')

Example:
MyChar='A'
print(ord(MyChar))#65

Example:
Example:
print(ord('स'))#2360
print(ord('ल'))#2354
print(ord('గ'))#3095

print(ord('‫))'ف‬#1601

chr(i)
Return the string representing a character whose Unicode code point is the integer i.

Syntax:
chr('number')

Example:
print(chr(65))#A
print(chr(90))#Z
print(chr(32))#
print(chr(49))#1
print(chr(123))#{

Example:
print(chr(2360))#स
print(chr(2354))#ल
print(chr(3095))#గ

print(chr(1601))#

Mnemonic Variable Names


This can confuse beginning students because well-named variables often “sound” so good.

Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)

Example:
a = 35.0;b = 12.50
c = a * b;print(c)

Writing numbers in Binary, Octal & HexaDecimal


Number System Prefix
Binary 0b or 0B
Octal 0o or 0O
Hexadecimal 0x or 0X

Binary literals (base 2)


Binary literals can easily be written as well. They have to be prefixed by a leading "0",
followed by a "b" or "B":

Syntax:
bin(number)

Example:
x = 0b101010
print(x )

Example
x = bin(65)
print(x)

Octal literals (base 8)


A number prefixed by 0o (zero and a lowercase "o" or uppercase "O") will be interpreted as
an octal number

Syntax:
oct(number)

Example:
a = 0o10
print(a)

Example
x = oct(65)
print(x)

Hexadecimal literals (base 16)


Hexadecimal literals have to be prefixed either by "0x" or "0X". (Zero followed by x or X)

Syntax:
hex(number)

Decimal ==> 0-9 (10)


Hexa ==> 6 ==> A/a =>10, B/b =>11, C/c =>12
D/d =>13, E/e =>14, F/f =>15 (6)
Hexa+Decimal=6+10=16

Example:
x = hex(19)
print(x)

Example:
x = hex(64)
print(x)

Example:Output of the following SCRIPT:


x=10;y=0o10;z=0X10
print(x);print(y);print(z)
a=0XAB;print(a)

None Data Type:


The None keyword is used to define a null value, or no value at all. If the value is not
available,then to handle such type of cases None introduced.

Example:
PySpe=None
print(type(PySpe))#<class 'NoneType'>
print(PySpe)#None

Order of Operations
When an expression contains more than one operator, the order of evaluation depends on
the order of operations. For mathematical operators, Python follows mathematical
convention. The acronym PEMDAS is a useful way.

PEMDAS
Parentheses Exponentiation Multiplication Division Addition Subtraction

Parentheses
2 * (3-1) ==> 4
(1+1)**(5-2) ==> 8

Exponentiation
1 + 2**3 ==> 9, not 27,
2 * 3**2 ==> 18, not 36.

Multiplication and Division have higher precedence than Addition and Subtraction.
2*3-1 ==> 5, not 4,
6+4/2 ==> 8, not 5.

Pdb Module (Python Debugger)


pdb is a debugging tool that is part of python’s standard library. It is an interactive source
code debugger for Python programs. Using pdb, we can set breakpoints at any point of our
program to stop it and check for errors or the status of our running program.

Syntax:
import pdb;
pdb.set_trace()

Example:
import pdb
print(dir(pdb))

PDB Options:
l (list) - Display 11 lines around the current line.
r (return) - Continue execution until the current function returns.
PYTHON SHELL PROGRAMMING:
ScriptRunMode/Dev. Mode
You can store code in a file and use the interpreter to execute the contents of the file, which
is called a script. Python scripts have names that end with .py Extension.

Example:
1. Goto IDLE, Select File and click on New or Ctrl+N (to Open New Window)
2. Enter required python statements or commands

print("Welcome to Script MODE")


print('Welcome to Dev MODE')
print("""It is a PYTHON Shelll""")
print('''Good Bye...!!''')
print(12345)

3. Save with .py Extension @ desired location


4. Hit the key F5 or Goto run menu click Run
5. The out put displayed in readonly format on the IDLE
6. Do required modifications in the saved file and re-run..!!

PYTHON File Other Extensions:


.py ==> Python File (Regular Scripts)
.py3 ==> (rarely used) Python3 script
.pyc==> This is the compiled bytecode/compiled scripts(Bytecode)
.pyd ==> This is basically a windows dll file
.pyo ==> This is optimized pyc file
.pyw==Python script for Windows
.pyz ==> Python script archive (Compressed or Zip formated)

SETTING PYTHON PATH IN Windows:


Right click on My Computer ==>Properties ==> Advanced System Settings ==>Environment
Variable ==>New
In Variable name write path and in Variable value.
>>> import os
>>> os.getcwd()
Displays PYTHON Installed Path, copy path without quotes ==> Click Ok ==>Ok.

Clear screen in Windows:


There is no python builtin command for IDLE to clear the screen. We can perform through
customized or userdefined commands..!!

>>> print("\n"*20)#displaying blank lines


>>> clear="\n"*20#Assign blank lines
>>> print(clear)#displaying blank lines

Working with Python in Unix & Linux Environments:


Define Unix?
Unix is a family of multitasking, multiuser computer operating systems. In Unix Python
default installed, It is called standard PYTHON.

$python ==> To open PYTHON prompt


$python -v ==> To display verbose info
$python --version ==> To display Version of PYTHON
$man python ==> To display Manual Pages of PY

In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen

In Unix Python can be executed in two Run Modes:


1. Interactive Run Mode ==> Command Mode
2. Script Run Mode ==> Shell Mode or Dev Mode
Execute a Python script (Interactive Run Mode)
$ python
>>> print("Hello World!")
>>> print "Hello World"
>>> x=raw_input("Enter Any Number: ")
>>> y=raw_input("Enter Any Number: ")
>>> x+y
>>> x=input("Enter Any Number: ")
>>> y=input("Enter Any Number: ")
>>> x+y
>>> import os
>>> os.getcwd()
>>> import platform
>>> platform.python_version()
>>> import keyword
>>> keyword.kwlist

2. Script Run Mode:


It is popularly known as Development mode. You can store code in a file and use the
interpreter to execute the contents of the file, which is called a script

What is Shebang?
The term shebang refers to the "#!" located at the top of many script files that points to the
path of the associated program. It has the following alias Names:
1. She-bang 2. Hashbang
3. Pound-bang 4. Hash-pling
5. Crunchbang....etc..!!

$which command:
It is used to display the path of interpreter or compiler, installed technology in UNIX.

Syntax:
$which <interpreter/compiler name>

Example:
$which python
/usr/bin/python
/ ==> root directory
usr ==> Default Directory
bin ==> Binary Directory
python ==> Name of the interpreter
Directory ==> Collection of sub-directories and files

Editors in UNIX:
Editor is a kind of ASCII formated file. It contains ANSI standard data like Alphabets,
Numbers and Special Characters. These are text formated files. In UNIX there are different
types editors are existed.
1. QUED ==> QUick EDitor
2. FRED ==> FRiendly EDitor
3. ED ==> standard EDitor
4. EX ==> EXtended editor/Advanced Editor
5. VI ==> VIsual editor
6. VIM ==> Visually IMproved editor ..................!!

The usage of #!/usr/bin/python plays a role if the script is executable, and called without the
preceding language.

Example:
$vi MyScript.py
$ ==> Unix User Prompt/Primary Prompt
# ==> Unix/Linux Admin/Super User Prompt
Prompt ==> User Interface
vi ==> Name of the Editor
MyScript ==> Name of the file
. ==> Embedded/Period character
py ==> Extension of the file

$vi MyScript.py ==> hit the return key (Enter)


vi contains the following three modes:
1. Command Mode: In this mode we can execute only shortcut keys.
2.Insert Mode:In this mode we can write logical statements.
3. ExCommandMode: In this mode we can execute the required script(s) or logic(s).

Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")

Hit the key Esc button, to convert into command mode.


hit the key :wq (Save and Exit)

Executing PYTHON Script:


$python MyScript.py (hit the return/enter key)
Output displayed..!!

INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.

Programmers View of Interpreter


Interpreter is a software, which takes source code, reads it line by line and executes it line by
line to produce the output.
Inside INTERPRETER
In Compiled languages are, compiler converts the source code into machine code or binary
code, which is directly executed by the machine. In PYTHON compiler is using to convert the
source code(.py) into byte code.(.pyc)

What is Byte Code in PYTHON?


Byte code is easily readable by PYTHON Virtual Machine and Source code easily
understandable by programmers.
1 Low Level
2 Platform Independent
3 Efficient
4 Intermediate
5 Representation of your source code

PVM is read the byte code line by line and execute every line and produce output. In that
process PVM uses all your Library Modules.

What are PYC files?


Python automatically compiles your script to compiled code, so called byte code, before
running it.
__pycache__:
It is a folder containing Python-3 byte-code compiled and ready to be executed.

Example:
import py_compile
print(dir(py_compile))

Example:
import compileall
print(dir(compileall))

Example:
import py_compile
py_compile.compile("MyScript.py")

Steps to Work with PYTHON INSIDE:


1. Create a Folder/Directory on the Desktop ( or in AnyLocation)
2. Create a py file in that folder
3. Go to command prompt, change to current Folder/Dir location
4. python and hit the return key
5. import py_compile
6.py_compile.compile("filename.py")
7. __pycache__ folder created automatically with byte code
8. cd __pycache__
9. python file.cpython-38.pyc, to execute byte code directly without source code

PYTHON RealTime IDEs


Define IDE?
Integrated Development Environment is a software application, that provides comprehensive
facilities to computer programmers for software development.

What is PyCharm?
It is the best IDE for realtime PYTHON projects. It provides code analysis, a graphical
debugger, an integrated unit tester and supports web development with Django framework.

PyCharm Come in two editions:


1 Community Edition (Fully-Free)
2 Professional Edition (Commercial-$199)

PyCharm IDE Installation:


1 Go to https://www.jetbrains.com/pycharm/download
OR
2 https://www.jetbrains.com/pycharm/promo/anaconda/
3 Install any Edition Community or Professional
4 It is cross-platform and works on Windows, macOS, and Linux.

PyCharm IDE Features List:


1 Intelligent Coding Assistance
2 Built-in Developer Tools
3 Web Development
4 Scientific Tools

Components of Pycharm:
It has maily the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window

How to create a project:


1. Goto file menu, click on New project, Enter name of the Project PYTHON_4PM
2. Select Current window
3. Right click on the project select Python file, enter name of the file.
4. Enter required python source code as follows

Example:
print("Hello Welcome to PYCHARM")
x=input("Enter any Number: ")
print(x)
import os
print(os.getcwd())
import sys
print(sys.platform)
print(sys.path)
import platform
print(platform.python_version())
import keyword
print(keyword.kwlist)

To run the code Ctrl+Shift+F10

Creating html files:


Right click on created project, select html file, enter required file name, click on ok.

Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Naresh i Technologies</title>
</head>
<body>
<h1 style="color:red;font-family:candara;text-decoration:line-through">Welcome to PYTHON
Django Environment </h1>
<h3>It is PYTHON Web Framework..!!</h3>
<marquee>
<img src="https://www.google.co.in/images/branding/googlelogo.png" width="100px"
height="100px"/>
</marquee>
</body>
</html>

Debugging in PYCHARM:
It is the process of identifying and fixing problems in Code. The following short-cut keys are
required to debug..!!
1 Step Over (F8)
2 Step Into (F7)
3 Force Step Into (Alt+Shift+F7)
4 Step Out (Shift+F8)
5 Run to Cursor (Alt+F9)

Example:
a=int(input("Enter Any Number: "))
b=int(input("Enter Any Number: "))
c=a+b
print("The Result is: ",c)
d=a-b
print("The Result is: ",d)
e=a*b
print("The Result is: ",e)
f=a/b
print("The Result is: ",f)
What is Anaconda?
The Most Popular Python Data Science Platform.
It is a freemium open source distribution of the Python and R PLs for large-scale data
processing, predictive analytics and scientific computing.

How to Install Anaconda?


1. https://www.anaconda.com/download/
2. Click on Python 3.7 version 64-Bit Installer download
3. After successful Installation of Anaconda Platform
4. Go to MSDOS Command Prompt type spyder or jupyter notebook
5. SPYDER(Scientific PYthon Development EnviRonment)
6. JUPYteR (formerly==>iPython(JUlia, PYthon and R)

Coding Environments
Anaconda comes with two popular IDEs :

Spyder:
It is a powerful IDE for the Python language with advanced editing, interactive testing,
debugging features..!!

General features:
1. iPython=>Enhanced interactive Python interpreter
2. NumPy =>Nummerical PYthon-Linear Algebra
3. SciPy=>Scientific Python-Signal & Image Processing
4. Matplotlib=>Interactive 2D/3D plotting
5. Pandas=>For Data Analysis with Data Frames
6. Scikit-learn==> It is a Machine Learning library

Spyder Shortcut Keys


1 Press F5 to run the entire script
2 Press F9 to run selection line
3 Press Ctrl + 1 to comment / uncomment
4 Ctrl+Enter executes the current cell.

Main Components in Spyder.


1 Dashboard 2 Project Explorer
3 Editor 4 Console 5 Help

What is Anaconda Navigator?


It is a desktop GUI, that allows you to launch applications and easily manage conda
packages without using command-line commands.

Jupyter Notebook:(http://jupyter.org/)
Formerly known as the IPython Notebook. It is a server-client application that allows editing
and running notebook documents via a web browser.

Features of Jupyter Notebook:


1 Edit/Run code in the browser
2 It supports 40+ Programming Languages
3 Share notebooks: using email, Dropbox, GitHub
4 BigData Integration

Example: (Plotting Examle)


import matplotlib.pyplot as plt
x=[1,2,3,4,5,10,11,12,30,31,89]
plt.plot(x,'bo-')
plt.xlabel("Time")
plt.ylabel("Price")
plt.show()

Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.

Goto Ancondata Prompt and do the follwing:


$conda update conda
$conda install numpy
$conda help
$conda help config
$conda help info

What is pip
It is a package manager for Python programming language.

Installation
$python get-pip.py

Syntax:
pip list [options]

Upgrading pip: UNIX:


$pip install -U pip

pip Commands:
$pip list $pip help $pip help install
$pip search django $pip install pympler
$pip uninstall django $pip show django
$pip download django $pip install virtualenv
https://pip.pypa.io/en/stable/reference/

What is PyDev?
PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython
development. http://www.pydev.org/

Define RODEO?
A Native Python IDE for Data Science
https://rodeo.yhat.com/

FAQs on Pre Core PYTHON:


1. Define Scripting?
2. Types of Scripts?
3. Diff between Programming Langs and Scripting Langs
4. Why Script?
5. Features and Limitation of Scripting?
6. Why script is Smart Programming?
7. What is Paradigm?
8. Define PYTHON?
9. Any Five features of PYTHON
10. Why Python is General Purpose programming?
11. Is Python complete language?
12. How and Who developed Python?
13. Python in Realtime?
14. Any Five Python Libs?
15. IDLE stands for
16. Name of the PYTHON Prompt?
17. How to clear screen in IDLE?
18. print() detailed syntax?
19. List any 10 PYTHON Keywords
20. How to display PYTHON version?
21. Single Lone Under score
22. How to Join lines in PYTHON?
23. What are the quotes in PYTHON?
24. How to configure shorcut keys in IDLE?
25. Write Comment notation?
26. PYTHON Interpreter Architecture?
27. How PYTHON generates ByteCode?
28. Write any five PYTHON file Extensions
29 What is Shell in PYTHON?
30 Define statement, command, os?
31. define IDE?
32. Define PYCHARM?
33. How to debug py script in PYCHARM?
34. Define Anaconda, Conda and Miniconda?
35. What is Spyder?
36. Write any three features of Spyder?
37. Why Jupyter Notebook?
38. What is Conda Lib?
39. How to use PiP?
40. Write any five PiP Commands?

Type Conversion or Type Casting:


Since Python is dynamically-typed, you may want to convert a value into another type. Every
value in Python has a data type.
Python Explicit Data Type Conversion
Primitive Data Structures:
Integers Float Strings Boolean
Non-Primitive Data Structures:
Lists Tuples Sets Dictionary

List of PYTHON Functions


1 int(x [,base]) 2 bool() 3 float(x)
4 str(x) 5 list(s)6 tuple(s)
7 set(s) 8 dict(d) 9 ord(x)
10 chr(x) 11 complex(real,img)
12 eval()

int(x [,base]):
It converts a number in given base to decimal.

Syntax:
int(string, base)

Parameter :
string : consists of 1's and 0's
base : (integer value) base of the number.

Example:
print(int(123))
print(int(123.098))
print(int(123.001))

Example:
print(int("1010",2))#10
print(int("1110",2))#14
print(int("1111",2))#15

Example:
print(int("12",8))#10
print(int("123",8))#83
print(int("34",8))#28

Example:
print(int("19",16))#25
print(int("4f",16))#79
print(int("98",16))#152

NOTE:
ValueError: int() base must be >= 2 and <= 36, or 0

Example:
print(int("111",2))#7
print(int("111",3))#13
print(int("111",4))#21
print(int("111",5))#31

bool()
It converts the value into a boolean.

Syntax:
bool(value)

The following values are considered false in Python:


None
False
Zero of any numeric type. For example, 0, 0.0, 0j
Empty sequence. For example, (), [], ''.
Empty mapping. For example, {}

NOTE: All other values except these values are considered true

Example:
print(bool([])); print(bool(['a value']))
print(bool('')); print(bool('A string'))
print(bool(True)); print(bool(False))
print(bool(0)); print(bool(None))
print(bool(0.0)); print(bool(1))

float(x): To convert x to a floating-point number.

Syntax:
float(value)

Example:
a=100
print(float(a))

NOTE:
We can convert any value to float type except complex type.

str() : It is Used to convert integer into a string.

Syntax:
str(value)

Example:
a=100
print(type(a)) #<class 'int'>
print(str(a))
print(type(a)) #<class 'str'>

NOTE:
If we want to convert str type to int type, string must contain only integral value.

list() :
It is used to convert any data type to a list type.

Syntax:
list(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyList=list(MyStr)
print(type(MyList))
print(MyList)

tuple() : It is used to convert to a tuple.

Syntax:
tuple(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyTuple=tuple(MyStr)
print(type(MyTuple))
print(MyTuple)

set() :
It returns the type after converting to set

Syntax:
set(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MySet=set(MyStr)
print(type(MySet))
print(MySet)

dict() :
It is used to convert a tuple of order (key,value) into a dictionary.

Syntax:
dict(key,value)
Example:
MyTup=(('a',1),('b',2),('c',3))
print(type(MyTup))
MyDict=dict(MyTup)
print(type(MyDict))
print(MyDict)

ord() :
It is used to convert a character to integer.

Syntax:
ord('Char')

Example:
MyChar='A'
print(ord(MyChar))#65

Example:
Example:
print(ord('स'))#2360
print(ord('ल'))#2354
print(ord('గ'))#3095

print(ord('‫))'ف‬#1601

chr(i)
Return the string representing a character whose Unicode code point is the integer i.

Syntax:
chr('number')

Example:
print(chr(65))#A
print(chr(90))#Z
print(chr(32))#
print(chr(49))#1
print(chr(123))#{

Example:
print(chr(2360))#स
print(chr(2354))#ल
print(chr(3095))#గ

print(chr(1601))#

Mnemonic Variable Names


This can confuse beginning students because well-named variables often “sound” so good.

Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)

Example:
a = 35.0;b = 12.50
c = a * b;print(c)

Writing numbers in Binary, Octal & HexaDecimal


Number System Prefix
Binary 0b or 0B
Octal 0o or 0O
Hexadecimal 0x or 0X

Binary literals (base 2)


Binary literals can easily be written as well. They have to be prefixed by a leading "0",
followed by a "b" or "B":

Syntax:
bin(number)

Example:
x = 0b101010
print(x )

Example
x = bin(65)
print(x)

Octal literals (base 8)


A number prefixed by 0o (zero and a lowercase "o" or uppercase "O") will be interpreted as
an octal number

Syntax:
oct(number)

Example:
a = 0o10
print(a)

Example
x = oct(65)
print(x)
Hexadecimal literals (base 16)
Hexadecimal literals have to be prefixed either by "0x" or "0X". (Zero followed by x or X)

Syntax:
hex(number)

Decimal ==> 0-9 (10)


Hexa ==> 6 ==> A/a =>10, B/b =>11, C/c =>12
D/d =>13, E/e =>14, F/f =>15 (6)
Hexa+Decimal=6+10=16

Example:
x = hex(19)
print(x)

Example:
x = hex(64)
print(x)

Example:Output of the following SCRIPT:


x=10;y=0o10;z=0X10
print(x);print(y);print(z)
a=0XAB;print(a)

None Data Type:


The None keyword is used to define a null value, or no value at all. If the value is not
available,then to handle such type of cases None introduced.

Example:
PySpe=None
print(type(PySpe))#<class 'NoneType'>
print(PySpe)#None

Order of Operations
When an expression contains more than one operator, the order of evaluation depends on
the order of operations. For mathematical operators, Python follows mathematical
convention. The acronym PEMDAS is a useful way.

PEMDAS
Parentheses Exponentiation Multiplication Division Addition Subtraction

Parentheses
2 * (3-1) ==> 4
(1+1)**(5-2) ==> 8

Exponentiation
1 + 2**3 ==> 9, not 27,
2 * 3**2 ==> 18, not 36.
Multiplication and Division have higher precedence than Addition and Subtraction.
2*3-1 ==> 5, not 4,
6+4/2 ==> 8, not 5.

Pdb Module (Python Debugger)


pdb is a debugging tool that is part of python’s standard library. It is an interactive source
code debugger for Python programs. Using pdb, we can set breakpoints at any point of our
program to stop it and check for errors or the status of our running program.

Syntax:
import pdb;
pdb.set_trace()

Example:
import pdb
print(dir(pdb))

PDB Options:
l (list) - Display 11 lines around the current line.
r (return) - Continue execution until the current function returns.
b (break) - Set a breakpoint (depending on the argument provided).
n (next) - Continue execution until the next line in the current function is reached.
s (step) - Execute the current line, stop at the first possible occasion.
j (jump) - Jump to the next line to be executed.
c (continue) - Creates a breakpoint in the program execution.
q (quit) Quit from the debugger. The program being executed is aborted.

Open run command, enter cmd


C:\cd desktop
C:\desktop\ notepad Hello.py
write required Python script, save it..!!
C:\desktop\python Hello.py
C:\desktop\python -m pdb Hello.py
> the prompt of the debugger
(pdb) l
List the lines of code..!!
b (break) - Set a breakpoint (depending on the argument provided).
n (next) - Continue execution until the next line in the current function is reached.
s (step) - Execute the current line, stop at the first possible occasion.
j (jump) - Jump to the next line to be executed.
c (continue) - Creates a breakpoint in the program execution.
q (quit) Quit from the debugger. The program being executed is aborted.

Open run command, enter cmd


C:\cd desktop
C:\desktop\ notepad Hello.py
write required Python script, save it..!!
C:\desktop\python Hello.py
C:\desktop\python -m pdb Hello.py
> the prompt of the debugger
(pdb) l
List the lines of code..!!
PYTHON SHELL PROGRAMMING:
ScriptRunMode/Dev. Mode
You can store code in a file and use the interpreter to execute the contents of the file, which
is called a script. Python scripts have names that end with .py Extension.

Example:
1. Goto IDLE, Select File and click on New or Ctrl+N (to Open New Window)
2. Enter required python statements or commands

print("Welcome to Script MODE")


print('Welcome to Dev MODE')
print("""It is a PYTHON Shelll""")
print('''Good Bye...!!''')
print(12345)

3. Save with .py Extension @ desired location


4. Hit the key F5 or Goto run menu click Run
5. The out put displayed in readonly format on the IDLE
6. Do required modifications in the saved file and re-run..!!

PYTHON File Other Extensions:


.py ==> Python File (Regular Scripts)
.py3 ==> (rarely used) Python3 script
.pyc==> This is the compiled bytecode/compiled scripts(Bytecode)
.pyd ==> This is basically a windows dll file
.pyo ==> This is optimized pyc file
.pyw==Python script for Windows
.pyz ==> Python script archive (Compressed or Zip formated)

SETTING PYTHON PATH IN Windows:


Right click on My Computer ==>Properties ==> Advanced System Settings ==>Environment
Variable ==>New
In Variable name write path and in Variable value.
>>> import os
>>> os.getcwd()
Displays PYTHON Installed Path, copy path without quotes ==> Click Ok ==>Ok.

Clear screen in Windows:


There is no python builtin command for IDLE to clear the screen. We can perform through
customized or userdefined commands..!!

>>> print("\n"*20)#displaying blank lines


>>> clear="\n"*20#Assign blank lines
>>> print(clear)#displaying blank lines

Working with Python in Unix & Linux Environments:


Define Unix?
Unix is a family of multitasking, multiuser computer operating systems. In Unix Python
default installed, It is called standard PYTHON.

$python ==> To open PYTHON prompt


$python -v ==> To display verbose info
$python --version ==> To display Version of PYTHON
$man python ==> To display Manual Pages of PY

In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen

In Unix Python can be executed in two Run Modes:


1. Interactive Run Mode ==> Command Mode
2. Script Run Mode ==> Shell Mode or Dev Mode

Execute a Python script (Interactive Run Mode)


$ python
>>> print("Hello World!")
>>> print "Hello World"
>>> x=raw_input("Enter Any Number: ")
>>> y=raw_input("Enter Any Number: ")
>>> x+y
>>> x=input("Enter Any Number: ")
>>> y=input("Enter Any Number: ")
>>> x+y
>>> import os
>>> os.getcwd()
>>> import platform
>>> platform.python_version()
>>> import keyword
>>> keyword.kwlist

2. Script Run Mode:


It is popularly known as Development mode. You can store code in a file and use the
interpreter to execute the contents of the file, which is called a script

What is Shebang?
The term shebang refers to the "#!" located at the top of many script files that points to the
path of the associated program. It has the following alias Names:
1. She-bang 2. Hashbang
3. Pound-bang 4. Hash-pling
5. Crunchbang....etc..!!

$which command:
It is used to display the path of interpreter or compiler, installed technology in UNIX.

Syntax:
$which <interpreter/compiler name>

Example:
$which python
/usr/bin/python
/ ==> root directory
usr ==> Default Directory
bin ==> Binary Directory
python ==> Name of the interpreter
Directory ==> Collection of sub-directories and files

Editors in UNIX:
Editor is a kind of ASCII formated file. It contains ANSI standard data like Alphabets,
Numbers and Special Characters. These are text formated files. In UNIX there are different
types editors are existed.
1. QUED ==> QUick EDitor
2. FRED ==> FRiendly EDitor
3. ED ==> standard EDitor
4. EX ==> EXtended editor/Advanced Editor
5. VI ==> VIsual editor
6. VIM ==> Visually IMproved editor ..................!!

The usage of #!/usr/bin/python plays a role if the script is executable, and called without the
preceding language.

Example:
$vi MyScript.py
$ ==> Unix User Prompt/Primary Prompt
# ==> Unix/Linux Admin/Super User Prompt
Prompt ==> User Interface
vi ==> Name of the Editor
MyScript ==> Name of the file
. ==> Embedded/Period character
py ==> Extension of the file

$vi MyScript.py ==> hit the return key (Enter)


vi contains the following three modes:
1. Command Mode: In this mode we can execute only shortcut keys.
2.Insert Mode:In this mode we can write logical statements.
3. ExCommandMode: In this mode we can execute the required script(s) or logic(s).

Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")

Hit the key Esc button, to convert into command mode.


hit the key :wq (Save and Exit)

Executing PYTHON Script:


$python MyScript.py (hit the return/enter key)
Output displayed..!!

INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.

Programmers View of Interpreter


Interpreter is a software, which takes source code, reads it line by line and executes it line by
line to produce the output.

Inside INTERPRETER
In Compiled languages are, compiler converts the source code into machine code or binary
code, which is directly executed by the machine. In PYTHON compiler is using to convert the
source code(.py) into byte code.(.pyc)

What is Byte Code in PYTHON?


Byte code is easily readable by PYTHON Virtual Machine and Source code easily
understandable by programmers.
1 Low Level
2 Platform Independent
3 Efficient
4 Intermediate
5 Representation of your source code

PVM is read the byte code line by line and execute every line and produce output. In that
process PVM uses all your Library Modules.

What are PYC files?


Python automatically compiles your script to compiled code, so called byte code, before
running it.
__pycache__:
It is a folder containing Python-3 byte-code compiled and ready to be executed.

Example:
import py_compile
print(dir(py_compile))

Example:
import compileall
print(dir(compileall))
Example:
import py_compile
py_compile.compile("MyScript.py")

Steps to Work with PYTHON INSIDE:


1. Create a Folder/Directory on the Desktop ( or in AnyLocation)
2. Create a py file in that folder
3. Go to command prompt, change to current Folder/Dir location
4. python and hit the return key
5. import py_compile
6.py_compile.compile("filename.py")
7. __pycache__ folder created automatically with byte code
8. cd __pycache__
9. python file.cpython-38.pyc, to execute byte code directly without source code

PYTHON RealTime IDEs


Define IDE?
Integrated Development Environment is a software application, that provides comprehensive
facilities to computer programmers for software development.

What is PyCharm?
It is the best IDE for realtime PYTHON projects. It provides code analysis, a graphical
debugger, an integrated unit tester and supports web development with Django framework.

PyCharm Come in two editions:


1 Community Edition (Fully-Free)
2 Professional Edition (Commercial-$199)

PyCharm IDE Installation:


1 Go to https://www.jetbrains.com/pycharm/download
OR
2 https://www.jetbrains.com/pycharm/promo/anaconda/
3 Install any Edition Community or Professional
4 It is cross-platform and works on Windows, macOS, and Linux.

PyCharm IDE Features List:


1 Intelligent Coding Assistance
2 Built-in Developer Tools
3 Web Development
4 Scientific Tools

Components of Pycharm:
It has maily the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window
How to create a project:
1. Goto file menu, click on New project, Enter name of the Project PYTHON_4PM
2. Select Current window
3. Right click on the project select Python file, enter name of the file.
4. Enter required python source code as follows

Example:
print("Hello Welcome to PYCHARM")
x=input("Enter any Number: ")
print(x)
import os
print(os.getcwd())
import sys
print(sys.platform)
print(sys.path)
import platform
print(platform.python_version())
import keyword
print(keyword.kwlist)

To run the code Ctrl+Shift+F10

Creating html files:


Right click on created project, select html file, enter required file name, click on ok.

Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Naresh i Technologies</title>
</head>
<body>
<h1 style="color:red;font-family:candara;text-decoration:line-through">Welcome to PYTHON
Django Environment </h1>
<h3>It is PYTHON Web Framework..!!</h3>
<marquee>
<img src="https://www.google.co.in/images/branding/googlelogo.png" width="100px"
height="100px"/>
</marquee>
</body>
</html>

Debugging in PYCHARM:
It is the process of identifying and fixing problems in Code. The following short-cut keys are
required to debug..!!
1 Step Over (F8)
2 Step Into (F7)
3 Force Step Into (Alt+Shift+F7)
4 Step Out (Shift+F8)
5 Run to Cursor (Alt+F9)

Example:
a=int(input("Enter Any Number: "))
b=int(input("Enter Any Number: "))
c=a+b
print("The Result is: ",c)
d=a-b
print("The Result is: ",d)
e=a*b
print("The Result is: ",e)
f=a/b
print("The Result is: ",f)

What is Anaconda?
The Most Popular Python Data Science Platform.
It is a freemium open source distribution of the Python and R PLs for large-scale data
processing, predictive analytics and scientific computing.

How to Install Anaconda?


1. https://www.anaconda.com/download/
2. Click on Python 3.7 version 64-Bit Installer download
3. After successful Installation of Anaconda Platform
4. Go to MSDOS Command Prompt type spyder or jupyter notebook
5. SPYDER(Scientific PYthon Development EnviRonment)
6. JUPYteR (formerly==>iPython(JUlia, PYthon and R)

Coding Environments
Anaconda comes with two popular IDEs :

Spyder:
It is a powerful IDE for the Python language with advanced editing, interactive testing,
debugging features..!!

General features:
1. iPython=>Enhanced interactive Python interpreter
2. NumPy =>Nummerical PYthon-Linear Algebra
3. SciPy=>Scientific Python-Signal & Image Processing
4. Matplotlib=>Interactive 2D/3D plotting
5. Pandas=>For Data Analysis with Data Frames
6. Scikit-learn==> It is a Machine Learning library

Spyder Shortcut Keys


1 Press F5 to run the entire script
2 Press F9 to run selection line
3 Press Ctrl + 1 to comment / uncomment
4 Ctrl+Enter executes the current cell.

Main Components in Spyder.


1 Dashboard 2 Project Explorer
3 Editor 4 Console 5 Help

What is Anaconda Navigator?


It is a desktop GUI, that allows you to launch applications and easily manage conda
packages without using command-line commands.

Jupyter Notebook:(http://jupyter.org/)
Formerly known as the IPython Notebook. It is a server-client application that allows editing
and running notebook documents via a web browser.

Features of Jupyter Notebook:


1 Edit/Run code in the browser
2 It supports 40+ Programming Languages
3 Share notebooks: using email, Dropbox, GitHub
4 BigData Integration

Example: (Plotting Examle)


import matplotlib.pyplot as plt
x=[1,2,3,4,5,10,11,12,30,31,89]
plt.plot(x,'bo-')
plt.xlabel("Time")
plt.ylabel("Price")
plt.show()

Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.

Goto Ancondata Prompt and do the follwing:


$conda update conda
$conda install numpy
$conda help
$conda help config
$conda help info

What is pip
It is a package manager for Python programming language.

Installation
$python get-pip.py

Syntax:
pip list [options]

Upgrading pip: UNIX:


$pip install -U pip

pip Commands:
$pip list $pip help $pip help install
$pip search django $pip install pympler
$pip uninstall django $pip show django
$pip download django $pip install virtualenv
https://pip.pypa.io/en/stable/reference/

What is PyDev?
PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython
development. http://www.pydev.org/

Define RODEO?
A Native Python IDE for Data Science
https://rodeo.yhat.com/

FAQs on Pre Core PYTHON:


1. Define Scripting?
2. Types of Scripts?
3. Diff between Programming Langs and Scripting Langs
4. Why Script?
5. Features and Limitation of Scripting?
6. Why script is Smart Programming?
7. What is Paradigm?
8. Define PYTHON?
9. Any Five features of PYTHON
10. Why Python is General Purpose programming?
11. Is Python complete language?
12. How and Who developed Python?
13. Python in Realtime?
14. Any Five Python Libs?
15. IDLE stands for
16. Name of the PYTHON Prompt?
17. How to clear screen in IDLE?
18. print() detailed syntax?
19. List any 10 PYTHON Keywords
20. How to display PYTHON version?
21. Single Lone Under score
22. How to Join lines in PYTHON?
23. What are the quotes in PYTHON?
24. How to configure shorcut keys in IDLE?
25. Write Comment notation?
26. PYTHON Interpreter Architecture?
27. How PYTHON generates ByteCode?
28. Write any five PYTHON file Extensions
29 What is Shell in PYTHON?
30 Define statement, command, os?
31. define IDE?
32. Define PYCHARM?
33. How to debug py script in PYCHARM?
34. Define Anaconda, Conda and Miniconda?
35. What is Spyder?
36. Write any three features of Spyder?
37. Why Jupyter Notebook?
38. What is Conda Lib?
39. How to use PiP?
40. Write any five PiP Commands?

Type Conversion or Type Casting:


Since Python is dynamically-typed, you may want to convert a value into another type. Every
value in Python has a data type.

Python Explicit Data Type Conversion


Primitive Data Structures:
Integers Float Strings Boolean
Non-Primitive Data Structures:
Lists Tuples Sets Dictionary

List of PYTHON Functions


1 int(x [,base]) 2 bool() 3 float(x)
4 str(x) 5 list(s)6 tuple(s)
7 set(s) 8 dict(d) 9 ord(x)
10 chr(x) 11 complex(real,img)
12 eval()

int(x [,base]):
It converts a number in given base to decimal.

Syntax:
int(string, base)

Parameter :
string : consists of 1's and 0's
base : (integer value) base of the number.

Example:
print(int(123))
print(int(123.098))
print(int(123.001))

Example:
print(int("1010",2))#10
print(int("1110",2))#14
print(int("1111",2))#15

Example:
print(int("12",8))#10
print(int("123",8))#83
print(int("34",8))#28

Example:
print(int("19",16))#25
print(int("4f",16))#79
print(int("98",16))#152

NOTE:
ValueError: int() base must be >= 2 and <= 36, or 0

Example:
print(int("111",2))#7
print(int("111",3))#13
print(int("111",4))#21
print(int("111",5))#31

bool()
It converts the value into a boolean.

Syntax:
bool(value)

The following values are considered false in Python:


None
False
Zero of any numeric type. For example, 0, 0.0, 0j
Empty sequence. For example, (), [], ''.
Empty mapping. For example, {}

NOTE: All other values except these values are considered true

Example:
print(bool([])); print(bool(['a value']))
print(bool('')); print(bool('A string'))
print(bool(True)); print(bool(False))
print(bool(0)); print(bool(None))
print(bool(0.0)); print(bool(1))

float(x): To convert x to a floating-point number.

Syntax:
float(value)

Example:
a=100
print(float(a))

NOTE:
We can convert any value to float type except complex type.

str() : It is Used to convert integer into a string.

Syntax:
str(value)

Example:
a=100
print(type(a)) #<class 'int'>
print(str(a))
print(type(a)) #<class 'str'>

NOTE:
If we want to convert str type to int type, string must contain only integral value.

list() :
It is used to convert any data type to a list type.

Syntax:
list(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyList=list(MyStr)
print(type(MyList))
print(MyList)

tuple() : It is used to convert to a tuple.

Syntax:
tuple(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MyTuple=tuple(MyStr)
print(type(MyTuple))
print(MyTuple)
set() :
It returns the type after converting to set

Syntax:
set(items)

Example:
MyStr="PYTHON"
print(type(MyStr))
MySet=set(MyStr)
print(type(MySet))
print(MySet)

dict() :
It is used to convert a tuple of order (key,value) into a dictionary.

Syntax:
dict(key,value)

Example:
MyTup=(('a',1),('b',2),('c',3))
print(type(MyTup))
MyDict=dict(MyTup)
print(type(MyDict))
print(MyDict)

ord() :
It is used to convert a character to integer.

Syntax:
ord('Char')

Example:
MyChar='A'
print(ord(MyChar))#65

Example:
Example:
print(ord('स'))#2360
print(ord('ल'))#2354
print(ord('గ'))#3095

print(ord('‫))'ف‬#1601

chr(i)
Return the string representing a character whose Unicode code point is the integer i.

Syntax:
chr('number')

Example:
print(chr(65))#A
print(chr(90))#Z
print(chr(32))#
print(chr(49))#1
print(chr(123))#{

Example:
print(chr(2360))#स
print(chr(2354))#ल
print(chr(3095))#గ

print(chr(1601))#

Mnemonic Variable Names


This can confuse beginning students because well-named variables often “sound” so good.

Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)

Example:
a = 35.0;b = 12.50
c = a * b;print(c)

Writing numbers in Binary, Octal & HexaDecimal


Number System Prefix
Binary 0b or 0B
Octal 0o or 0O
Hexadecimal 0x or 0X

Binary literals (base 2)


Binary literals can easily be written as well. They have to be prefixed by a leading "0",
followed by a "b" or "B":

Syntax:
bin(number)

Example:
x = 0b101010
print(x )

Example
x = bin(65)
print(x)

Octal literals (base 8)


A number prefixed by 0o (zero and a lowercase "o" or uppercase "O") will be interpreted as
an octal number

Syntax:
oct(number)

Example:
a = 0o10
print(a)

Example
x = oct(65)
print(x)

Hexadecimal literals (base 16)


Hexadecimal literals have to be prefixed either by "0x" or "0X". (Zero followed by x or X)

Syntax:
hex(number)

Decimal ==> 0-9 (10)


Hexa ==> 6 ==> A/a =>10, B/b =>11, C/c =>12
D/d =>13, E/e =>14, F/f =>15 (6)
Hexa+Decimal=6+10=16

Example:
x = hex(19)
print(x)

Example:
x = hex(64)
print(x)

Example:Output of the following SCRIPT:


x=10;y=0o10;z=0X10
print(x);print(y);print(z)
a=0XAB;print(a)

None Data Type:


The None keyword is used to define a null value, or no value at all. If the value is not
available,then to handle such type of cases None introduced.

Example:
PySpe=None
print(type(PySpe))#<class 'NoneType'>
print(PySpe)#None

Order of Operations
When an expression contains more than one operator, the order of evaluation depends on
the order of operations. For mathematical operators, Python follows mathematical
convention. The acronym PEMDAS is a useful way.

PEMDAS
Parentheses Exponentiation Multiplication Division Addition Subtraction

Parentheses
2 * (3-1) ==> 4
(1+1)**(5-2) ==> 8

Exponentiation
1 + 2**3 ==> 9, not 27,
2 * 3**2 ==> 18, not 36.

Multiplication and Division have higher precedence than Addition and Subtraction.
2*3-1 ==> 5, not 4,
6+4/2 ==> 8, not 5.

Pdb Module (Python Debugger)


pdb is a debugging tool that is part of python’s standard library. It is an interactive source
code debugger for Python programs. Using pdb, we can set breakpoints at any point of our
program to stop it and check for errors or the status of our running program.

Syntax:
import pdb;
pdb.set_trace()

Example:
import pdb
print(dir(pdb))

PDB Options:
l (list) - Display 11 lines around the current line.
r (return) - Continue execution until the current function returns.
b (break) - Set a breakpoint (depending on the argument provided).
n (next) - Continue execution until the next line in the current function is reached.
s (step) - Execute the current line, stop at the first possible occasion.
j (jump) - Jump to the next line to be executed.
c (continue) - Creates a breakpoint in the program execution.
q (quit) Quit from the debugger. The program being executed is aborted.

Open run command, enter cmd


C:\cd desktop
C:\desktop\ notepad Hello.py
write required Python script, save it..!!
C:\desktop\python Hello.py
C:\desktop\python -m pdb Hello.py
> the prompt of the debugger
(pdb) l
List the lines of code..!!

You might also like