Python Shell Programming
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
In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen
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
Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")
INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.
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)
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.
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
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.
Components of Pycharm:
It has maily the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window
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)
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.
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
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.
Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.
What is pip
It is a package manager for Python programming language.
Installation
$python get-pip.py
Syntax:
pip list [options]
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/
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)
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))
Syntax:
float(value)
Example:
a=100
print(float(a))
NOTE:
We can convert any value to float type except complex type.
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)
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))#
Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)
Example:
a = 35.0;b = 12.50
c = a * b;print(c)
Syntax:
bin(number)
Example:
x = 0b101010
print(x )
Example
x = bin(65)
print(x)
Syntax:
oct(number)
Example:
a = 0o10
print(a)
Example
x = oct(65)
print(x)
Syntax:
hex(number)
Example:
x = hex(19)
print(x)
Example:
x = hex(64)
print(x)
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.
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
In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen
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
Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")
INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.
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.
Example:
import py_compile
print(dir(py_compile))
Example:
import compileall
print(dir(compileall))
Example:
import py_compile
py_compile.compile("MyScript.py")
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.
Components of Pycharm:
It has maily the following Components:
1. Menu or Dashboard
2. Project Panel
3. Code Editor
4. Console or Output Window
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)
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.
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
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.
Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.
What is pip
It is a package manager for Python programming language.
Installation
$python get-pip.py
Syntax:
pip list [options]
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/
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)
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))
Syntax:
float(value)
Example:
a=100
print(float(a))
NOTE:
We can convert any value to float type except complex type.
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)
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))#
Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)
Example:
a = 35.0;b = 12.50
c = a * b;print(c)
Syntax:
bin(number)
Example:
x = 0b101010
print(x )
Example
x = bin(65)
print(x)
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)
Example:
x = hex(19)
print(x)
Example:
x = hex(64)
print(x)
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.
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.
Example:
1. Goto IDLE, Select File and click on New or Ctrl+N (to Open New Window)
2. Enter required python statements or commands
In UNIX
>>> CTRL + L #NoBlankLines, Clear the screen
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
Example:
#!/usr/bin/python
print("Hello Welcome to PYTHON with Unix")
print('It is standard PYTHON')
print '''Good Bye'''
print("Thank U")
INSIDE PYTHON
After successful installation of Python, It is the combination of Interpreter and Support
Library.
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)
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.
Example:
import py_compile
print(dir(py_compile))
Example:
import compileall
print(dir(compileall))
Example:
import py_compile
py_compile.compile("MyScript.py")
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.
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)
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.
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
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.
Define Conda?
It is an open source package management system and environment management system
for installing multiple versions of software packages.
What is pip
It is a package manager for Python programming language.
Installation
$python get-pip.py
Syntax:
pip list [options]
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/
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)
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))
Syntax:
float(value)
Example:
a=100
print(float(a))
NOTE:
We can convert any value to float type except complex type.
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)
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))#
Example:
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print(x1q3p9afd)
Example:
a = 35.0;b = 12.50
c = a * b;print(c)
Syntax:
bin(number)
Example:
x = 0b101010
print(x )
Example
x = bin(65)
print(x)
Syntax:
oct(number)
Example:
a = 0o10
print(a)
Example
x = oct(65)
print(x)
Syntax:
hex(number)
Example:
x = hex(19)
print(x)
Example:
x = hex(64)
print(x)
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.
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.