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

BASIC

PYTHON
AGENDA
- Introduction
- Install Visual studio code/ python
- Variable
- Comparison Operators
- if else
- loop
- List, Dictionary
- Read Write File
- Library paramiko
- Code Backup Fortigate
- Code Config Fortigate
2
SETUP(1)
SETUP(1)
SETUP(2)
SETUP(3)
Setting VS Code
Variable
• เป็ นการสร้างตัวแปรเพื่อมาเก็บค่าบางอย่าง โดยจะใช้ชื่อให้สื่อความกับสิ่ งเราต้องการจะเก็บ เช่น

แต่ขอ้ ห้ามในการตั้งคือ ไม่ควรจะตั้งชื่อซ้ ากับ Function ใน Python เช่น str,int,max,sum เป็ นต้น
String
Syntax :

a =“hello”
a= ‘hello’
Int,Float
Syntax :

a=1
a=-10
Syntax :

a = 1.2
a=-10.22
Comparison Operators
Python if else

Syntax :
if(statement):
print(“True”)
else:
print(“false”)
For Loops
•syntax
•List1 =[1,2,3,4,5,6,7]
•for num in List1 :
•print(num)
While loops

•Syntax :
• count = 0
• while count < 5:
• print(count)
• count +=1
Lists

•Syntax:
• List =[value1,value2,value3,….valueN]
Dictionary

Syntax :
dic
={key1:value1,key2:value2,….keyN:valueN}
Files I/O
Files I/O
• Syntax :
• File = open(filename,’r’)
• Read_file=File.read()
• File.close()
• Print(Read_file)
• ###############################
• File = open(filename,’w’)
• File = write(“hi SNK”)
• File.close()
การเชื่ อมต่ ออุปกรณ์ Network

- Telnet (port 23)


- SSH (port 22)
- API (http,https)
PIP
• Pip install telnetlib
• Pip install netmiko
Reference
• https://www.tutorialspoint.com/python/index.htm
• https://www.learnpython.org/
• https://www.geeksforgeeks.org/
• http://marcuscode.com/lang/python/
• https://docs.python.org/3.1/library/
• https://github.com/ktbyers/netmiko

You might also like