Sunteți pe pagina 1din 17

Python/Programing Bootcamp

Network Automation Bonus


Spandan Naik (GDC B'lore)
April 2016
Elephant in the room
PYTHON
Agenda

Installation / Environment Setup

Basic Operators, Decision Making & Loops

Function, Files I/O, Exception Handling

Classes & Objects

Regular Expressions
Installation / Environment
Setup
Python 2.7.11
https://www.python.org/ftp/python/2.7.11/python-2.7.11.msi (windows)
https://www.python.org/ftp/python/2.7.11/python-2.7.11-macosx10.6.pkg (mac OS-X)

Eclipse
Release : Mars

PyDev
Python IDE for Eclipse
Basic Operators, Decision
Making & Loops
Variable Types
Numbers
int (signed integers)
long (long integers, they can also be represented in octal and hexadecimal)
float (floating point real values)
complex (complex numbers)

String
List (Lists similar to arrays in c, but can have different data type)

Tuple (Similar to List but cannot be updated or changed)


Dictionary (Hash table type, consists of key-value pairs)
Basic Operators
Arithmetic Operator ( +, -, *, /, %, **, // )
Comparison Operator ( ==, !=, >, <, >=, <= )
Assignment Operator ( = , +=, -=, *=, /=, %=, **=, //= )
Logical Operator ( and, or, not )
Membership Operator ( in, not in)
Operators Precedence
(http://www.tutorialspoint.com/python/operators_precedence_example.htm)
Decision Making
If statement
Else statement
Elif statement
Loops
While expression:
Statement(s)

For iterating_var in sequence:


Statement(s)

Nested Loops
Break
Continue
Pass
Function, Files I/O,
Exception Handling
Function

A function is a block of organized, reusable code that is


used to perform a single, related action.

def functionname( parameters ):


"function_docstring"
function_suite
return [expression]
Files I/O

User Input
Raw_input
Input

Opening and Closing files


Writing into a file
Reading from a file
Creating Directory
Removing Directory
Exception Handling

Try try:
You do your operations here;
Except except ExceptionI:
If there is ExceptionI, then execute this block.
Else except ExceptionII:
If there is ExceptionII, then execute this block.
Finally except:
If there is any exception, then execute this block
else:
If there is no exception then execute this block.
finally:
This would always be executed.
Regular Expressions

S-ar putea să vă placă și