Python PPT

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Python Basics

Abishek R. S.

Jan 28, 2020

1 / 10
Features of Python

• Open Source

• Case Sensitive

• No Variable declaration (unlike C++)

• Uses zero indexing

• Comments start with #

2 / 10
Rules for Naming variables

• Cannot be a keyword
for = 12

• Cannot start with a digit


5bus = 23

• Cannot have special characters like !, @, #, $, %


bus$ = 15

• Cannot have spaces


bus type = 1
Instead use under score
bus type = 1
3 / 10
Common Data Types
• Strings : Sequence of characters. Enclosed within single or double
qoutes
s1 = "hello" s2 = ‘python’

• Numbers: Three types integers, real numbers and complex numbers


a = 12 b = 0.2 c = 1 + 2j

• Lists: Ordered sequence of items


a = ["hello", 1, 2+3j]
a[i] to access item at index i

• Dictionary: Mapping
a = {"Hoody" : 434003 , "Gooty": 414001 }
a["Hoody"] to access bus number of Hoody
4 / 10
Common Operators

• Assignment operator: Used to assign value to a variable


a = -34.6

• Arithmetic operators: Used for math operations


a+b, a-b, a*b, a/b, a%b

• Relational operators: Used to compare values. Returns boolean value


a>b, a<b, a==b, a! =b

• Logical operators: Operates on boolean values


a and b, a or b, not a

5 / 10
If Else loop

Syntax:

if condition1:
code1
elif condition2:
code2
else:
code3

Indentation is very important. No braces like C++

6 / 10
For loop

Used when a task has to be performed a known number of times.

Syntax:

for i in range(start, stop, step):


code

Indentation is very important. No braces like C++

Default step is 1 and Default Start is 0

7 / 10
While loop

Used when a task has to be performed a unknown number of times (as


long as the specified condition is satisfied).

Syntax:

while condition:
code

Indentation is very important. No braces like C++

Condition should be carefully chosen to prevent infinite loops

8 / 10
Commonly used functions

• case : Load PSS/E .sav file

• bsys : Create Subsystem

• fnsl : Run Full Newton Raphson Load flow solution

• sav : Save PSS/E case in .sav format

• tree : To check for islands with swing bus

9 / 10
Commonly used functions (Dynamics)

• cong, conl : Convert generators and loads

• ordr, fact : Ordering and Factorizing

• dyre new : Load PSS/E .dyr file

• chsb : Define output channels

• strt : Initialization

• run : Run simulation

10 / 10

You might also like