SlideShare a Scribd company logo
PYTHON OVERVIEW
Why Python?
 Simple
 Powerful
 Usually preinstalled
 Less Syntax
 Open Source
 Plethora of PenTestTools already created
Interpreted?
• Python is interpreted, which means that python code is translated
and executed by an interpreter one statement at a time.
• This means you can run commands/code on the command
prompt…
• Through a command
prompt with a text file…
• Using an IDE
What Does It Look Like?
Good programming proclamations
 Using comments to denote programs or sections of code
◦ A comment beginning with # is called a single-line comment because it
terminates at the end of the current line.
◦ You also may use a multi-line comment—possibly containing many
lines—begins with ’’’ and ends with ’’’.
 You use blank lines, space characters and tab characters (i.e., “tabs”)
to make programs easier to read.
◦ Together, these characters are known as white space.
◦ White-space characters are USUALLY ignored by the interpreter.
◦ Python has its own rules with white space
Printing a Line of Text
• Code: print(“ “) Python 3
• Code: print “ “ Python 2
• Anything placed inside the quotes will be printed on the screen upon execution
of the print command.
Output
Obtaining input
 How to input values from the user
› Code: variable = input(“Prompt “) Python 3
› Code: variable = raw_input(“Prompt”) Python 2
› variable – stores the input from the user.
› input – function to extract user input from the command prompt.
› “Prompt” – a string to inform the user of the type of value to enter.
 Ex. Inputting a numerical value
testGrade1 = input(”Enter test grade 1: “)
testGrade *= 100
print(”Test Grade: “, testGrade, “%”)
Good Programming:Organize outputs, good prompts
DataType Conversion
• Can control how variables are interpreted within the
program:
• Evaluation
• Code: eval(string)
• Ex. eval(“51” + “52”)
• eval( str1 ** str2)
• test = eval(input(“Enter a num”))
Conditional Operators
• Operator Meaning
• == equal to
• < less than
• <= less than or equals to
• > greater than
• >= greater than or equal to
• != not equal to
• Common Mistake:Confusing = with ==
Decision Structures
• Code:
Creating a decision structure:
if (expression):
statement
• To execute more than one statement in a block they must be indented equally:
if (score > 90):
grade = 'A'
print(“Good Job!n”)
print(“Not part of the conditions execution”)
• Good Programming: Commenting conditional blocks
• Common Mistakes: Forgetting equal indent, forgetting :, and forgetting space after if
• Good Practices: Use a tab not a space (harder to line up and troubleshoot)
Space Indent
Nested Conditionals
if (condition):
Statement
elif (condition):
Statement
elif (condition):
Statement
Statement
else:
Statement
• Common Errors: Not Lining up Else with its preceding If.
• Question:Why is a trailing else good programming?
Nested if/else if Example
Question: What zodiac sign is it for the current year?
Logical Operators
Code:
• Using logical operators:
• if (condition or condition)
Statement
• if (condition and condition)
Statement
While Loops
• AWhile Loop is a loop that executes 0 or more times before
terminating.
• Pre-conditional loop
 Code:
 Creating aWhile Loop:
 while (condition statement):
statement1
statement2
 DebuggingTechniques:
 Setup a counter to keep track of the number of times a loop runs
 Set up a counter to count if an event is occurring or the number of
times it occurs
 Output values each time a loop executes
Example
num = eval(input(“Enter a number less than 10:”))
while (num >= 10):
print(“Invalid Entry!”)
num = eval(input(“Enter a number less than 10:”))
For Loops
• For loops are a pre-test loop
• In order to utilize a for loop you need 3 things:
1. Needs to initialize a counter
2. Must test the counter variable (less than)
3. It must update the counter variable
• Code:
for initialization in range(start, stop, increment):
statement1
statement2
Example
for i in range(0, 5, 1):
print(“Hello”)
Step 1: Perform the initialization
expression
Step 2: Evaluate the test expressions
Step 3: Execute the body of the
loop
Step 4: Perform the
update
Assign 0 to i
i < 5
Update iPrint “Hello”
True
False
Function Definition
• Definition includes:
• return value: the value the function returns to the part of the
program that called it
• name: name of the function. Function names follow same rules
as variables
• parameter list: variables containing
values passed to the function
• body: statements that perform
the function’s task
Calling a Function
• Functions just like variables need to be called in order
to be invoked
• Code:
Calling a Function:
 functionName (Parameters)
Write and Calling Functions Example
Modules
• Some special functions have not been innately included into the interpreter to
speed up the loading process, these packages are known as modules.
• Code: import moduleName
• Ex.
• import math
• import random
• Import os
• OS module
• os.getcwd()
• os.chdir(path)

More Related Content

PPTX
Introduction to python
PDF
Basic Concepts in Python
PPTX
Python basics
PPT
Introduction to Python
PPTX
Python Tutorial Part 1
PDF
Introduction to python programming
PDF
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
PDF
Datatypes in python
Introduction to python
Basic Concepts in Python
Python basics
Introduction to Python
Python Tutorial Part 1
Introduction to python programming
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Datatypes in python

What's hot (20)

PDF
Introduction To Python | Edureka
PDF
Python Basics | Python Tutorial | Edureka
PPTX
PPTX
Python - An Introduction
PPTX
Python in 30 minutes!
PDF
Python Tutorial
PDF
Get started python programming part 1
PPTX
Fundamentals of Python Programming
PPTX
Beginning Python Programming
PPTX
Introduction python
PPTX
Basics of python
PPTX
Basic Python Programming: Part 01 and Part 02
PDF
Introduction To Programming with Python
PDF
Python Programming Tutorial | Edureka
PDF
Python final ppt
PPTX
Introduction to-python
PPT
Introduction to Python
PPT
Python Programming ppt
Introduction To Python | Edureka
Python Basics | Python Tutorial | Edureka
Python - An Introduction
Python in 30 minutes!
Python Tutorial
Get started python programming part 1
Fundamentals of Python Programming
Beginning Python Programming
Introduction python
Basics of python
Basic Python Programming: Part 01 and Part 02
Introduction To Programming with Python
Python Programming Tutorial | Edureka
Python final ppt
Introduction to-python
Introduction to Python
Python Programming ppt
Ad

Viewers also liked (20)

PPTX
Processing Regex Python
PPTX
Reading and Writing Files
PPTX
CSV File Manipulation
PPTX
PPTX
Sending Email
PPTX
Web Scraping
PPTX
More Perl Basics
PPTX
More Pattern Matching With RegEx
PPTX
File I/O
PPTX
Processing with Regular Expressions
PPTX
Matching with Regular Expressions
PPTX
Passing Arguments
PPTX
Regular Expressions
PPTX
Subroutines
PPTX
Basic .Net Training in Hyderabad
KEY
PHP to Python with No Regrets
PPTX
presentation on Unix basic by prince kumar kushwhaha
PDF
Python Programming - II. The Basics
PPT
Introduction To Unix
PPT
Python Intro For Managers
Processing Regex Python
Reading and Writing Files
CSV File Manipulation
Sending Email
Web Scraping
More Perl Basics
More Pattern Matching With RegEx
File I/O
Processing with Regular Expressions
Matching with Regular Expressions
Passing Arguments
Regular Expressions
Subroutines
Basic .Net Training in Hyderabad
PHP to Python with No Regrets
presentation on Unix basic by prince kumar kushwhaha
Python Programming - II. The Basics
Introduction To Unix
Python Intro For Managers
Ad

Similar to Python Basics (20)

PPTX
Python programing
PPTX
Bikalpa_Thapa_Python_Programming_(Basics).pptx
PPTX
made it easy: python quick reference for beginners
PDF
python notes.pdf
PDF
pythonQuick.pdf
PDF
python 34💭.pdf
PPT
Help with Pyhon Programming Homework
PPTX
lecture 2.pptx
ODP
Introduction to Python - Training for Kids
PPT
python fundamental for beginner course .ppt
PDF
python.pdf
PDF
Python unit 2 M.sc cs
PPTX
Python
PPTX
#Code2Create: Python Basics
PPTX
Programming with python
PDF
Pythonintro
PPTX
python-presentationpython-presentationpython-presentation.pptx
PPTX
Building arcade game using python workshop
PPTX
Introduction To Python.pptx
PPTX
PYTHON PROGRAMMING
Python programing
Bikalpa_Thapa_Python_Programming_(Basics).pptx
made it easy: python quick reference for beginners
python notes.pdf
pythonQuick.pdf
python 34💭.pdf
Help with Pyhon Programming Homework
lecture 2.pptx
Introduction to Python - Training for Kids
python fundamental for beginner course .ppt
python.pdf
Python unit 2 M.sc cs
Python
#Code2Create: Python Basics
Programming with python
Pythonintro
python-presentationpython-presentationpython-presentation.pptx
Building arcade game using python workshop
Introduction To Python.pptx
PYTHON PROGRAMMING

More from primeteacher32 (20)

PPT
Software Development Life Cycle
PPTX
Variable Scope
PPTX
Returning Data
PPTX
Intro to Functions
PPTX
Introduction to GUIs with guizero
PPTX
Function Parameters
PPTX
Nested Loops
PPT
Conditional Loops
PPTX
Introduction to Repetition Structures
PPTX
Input Validation
PPTX
Windows File Systems
PPTX
Nesting Conditionals
PPTX
Conditionals
PPT
Intro to Python with GPIO
PPTX
Variables and Statements
PPTX
Variables and User Input
PPT
Intro to Python
PPTX
Raspberry Pi
PPT
Hardware vs. Software Presentations
PPTX
Block chain security
Software Development Life Cycle
Variable Scope
Returning Data
Intro to Functions
Introduction to GUIs with guizero
Function Parameters
Nested Loops
Conditional Loops
Introduction to Repetition Structures
Input Validation
Windows File Systems
Nesting Conditionals
Conditionals
Intro to Python with GPIO
Variables and Statements
Variables and User Input
Intro to Python
Raspberry Pi
Hardware vs. Software Presentations
Block chain security

Recently uploaded (20)

PDF
Manager Resume for R, CL & Applying Online.pdf
PDF
MCQ Practice CBT OL Official Language 1.pptx.pdf
PDF
esg-supply-chain-webinar-nov2018hkhkkh.pdf
PPTX
internship presentation of bsnl in colllege
PPTX
1751884730-Visual Basic -Unitj CS B.pptx
PPTX
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
PPTX
PMP (Project Management Professional) course prepares individuals
PDF
Daisia Frank: Strategy-Driven Real Estate with Heart.pdf
PPTX
Surgical thesis protocol formation ppt.pptx
PPTX
Overview Planner of Soft Skills in a single ppt
PPTX
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
PPTX
Definition and Relation of Food Science( Lecture1).pptx
DOCX
mcsp232projectguidelinesjan2023 (1).docx
PPTX
E-Commerce____Intermediate_Presentation.pptx
PPTX
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
PPTX
Prokaryotes v Eukaryotes PowerPoint.pptx
PPT
BCH3201 (Enzymes and biocatalysis)-JEB (1).ppt
PDF
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
PPTX
Sports and Dance -lesson 3 powerpoint presentation
PPTX
A slide for students with the advantagea
Manager Resume for R, CL & Applying Online.pdf
MCQ Practice CBT OL Official Language 1.pptx.pdf
esg-supply-chain-webinar-nov2018hkhkkh.pdf
internship presentation of bsnl in colllege
1751884730-Visual Basic -Unitj CS B.pptx
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
PMP (Project Management Professional) course prepares individuals
Daisia Frank: Strategy-Driven Real Estate with Heart.pdf
Surgical thesis protocol formation ppt.pptx
Overview Planner of Soft Skills in a single ppt
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
Definition and Relation of Food Science( Lecture1).pptx
mcsp232projectguidelinesjan2023 (1).docx
E-Commerce____Intermediate_Presentation.pptx
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
Prokaryotes v Eukaryotes PowerPoint.pptx
BCH3201 (Enzymes and biocatalysis)-JEB (1).ppt
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
Sports and Dance -lesson 3 powerpoint presentation
A slide for students with the advantagea

Python Basics

  • 2. Why Python?  Simple  Powerful  Usually preinstalled  Less Syntax  Open Source  Plethora of PenTestTools already created
  • 3. Interpreted? • Python is interpreted, which means that python code is translated and executed by an interpreter one statement at a time. • This means you can run commands/code on the command prompt… • Through a command prompt with a text file… • Using an IDE
  • 4. What Does It Look Like?
  • 5. Good programming proclamations  Using comments to denote programs or sections of code ◦ A comment beginning with # is called a single-line comment because it terminates at the end of the current line. ◦ You also may use a multi-line comment—possibly containing many lines—begins with ’’’ and ends with ’’’.  You use blank lines, space characters and tab characters (i.e., “tabs”) to make programs easier to read. ◦ Together, these characters are known as white space. ◦ White-space characters are USUALLY ignored by the interpreter. ◦ Python has its own rules with white space
  • 6. Printing a Line of Text • Code: print(“ “) Python 3 • Code: print “ “ Python 2 • Anything placed inside the quotes will be printed on the screen upon execution of the print command.
  • 8. Obtaining input  How to input values from the user › Code: variable = input(“Prompt “) Python 3 › Code: variable = raw_input(“Prompt”) Python 2 › variable – stores the input from the user. › input – function to extract user input from the command prompt. › “Prompt” – a string to inform the user of the type of value to enter.  Ex. Inputting a numerical value testGrade1 = input(”Enter test grade 1: “) testGrade *= 100 print(”Test Grade: “, testGrade, “%”) Good Programming:Organize outputs, good prompts
  • 9. DataType Conversion • Can control how variables are interpreted within the program: • Evaluation • Code: eval(string) • Ex. eval(“51” + “52”) • eval( str1 ** str2) • test = eval(input(“Enter a num”))
  • 10. Conditional Operators • Operator Meaning • == equal to • < less than • <= less than or equals to • > greater than • >= greater than or equal to • != not equal to • Common Mistake:Confusing = with ==
  • 11. Decision Structures • Code: Creating a decision structure: if (expression): statement • To execute more than one statement in a block they must be indented equally: if (score > 90): grade = 'A' print(“Good Job!n”) print(“Not part of the conditions execution”) • Good Programming: Commenting conditional blocks • Common Mistakes: Forgetting equal indent, forgetting :, and forgetting space after if • Good Practices: Use a tab not a space (harder to line up and troubleshoot) Space Indent
  • 12. Nested Conditionals if (condition): Statement elif (condition): Statement elif (condition): Statement Statement else: Statement • Common Errors: Not Lining up Else with its preceding If. • Question:Why is a trailing else good programming?
  • 13. Nested if/else if Example Question: What zodiac sign is it for the current year?
  • 14. Logical Operators Code: • Using logical operators: • if (condition or condition) Statement • if (condition and condition) Statement
  • 15. While Loops • AWhile Loop is a loop that executes 0 or more times before terminating. • Pre-conditional loop  Code:  Creating aWhile Loop:  while (condition statement): statement1 statement2  DebuggingTechniques:  Setup a counter to keep track of the number of times a loop runs  Set up a counter to count if an event is occurring or the number of times it occurs  Output values each time a loop executes
  • 16. Example num = eval(input(“Enter a number less than 10:”)) while (num >= 10): print(“Invalid Entry!”) num = eval(input(“Enter a number less than 10:”))
  • 17. For Loops • For loops are a pre-test loop • In order to utilize a for loop you need 3 things: 1. Needs to initialize a counter 2. Must test the counter variable (less than) 3. It must update the counter variable • Code: for initialization in range(start, stop, increment): statement1 statement2
  • 18. Example for i in range(0, 5, 1): print(“Hello”) Step 1: Perform the initialization expression Step 2: Evaluate the test expressions Step 3: Execute the body of the loop Step 4: Perform the update Assign 0 to i i < 5 Update iPrint “Hello” True False
  • 19. Function Definition • Definition includes: • return value: the value the function returns to the part of the program that called it • name: name of the function. Function names follow same rules as variables • parameter list: variables containing values passed to the function • body: statements that perform the function’s task
  • 20. Calling a Function • Functions just like variables need to be called in order to be invoked • Code: Calling a Function:  functionName (Parameters)
  • 21. Write and Calling Functions Example
  • 22. Modules • Some special functions have not been innately included into the interpreter to speed up the loading process, these packages are known as modules. • Code: import moduleName • Ex. • import math • import random • Import os • OS module • os.getcwd() • os.chdir(path)

Editor's Notes

  • #3: Read Introduction from Violent Python pg.1 -2 Perl is complex and has too many idiosyncrasies even though many prebuilt tools are designed in perl so modification is huge Java and C are system languages and need to be comipled Python is a general purpose programming language. That means you can use Python to write code for any programming tasks. Google search engine Mission critical projects in NASA, Processing financial transactions at New York Stock Exchange. Data Analytics
  • #5: Common elements in programming languages: Key Words Programmer-Defined Identifiers Operators Punctuation Syntax
  • #19: Loop Directories???
  • #23: Additionally, new functionality is added to the language all the time as it is created.