SlideShare a Scribd company logo
1 of 37
Python Programming
Design Tools: Algorithms, Flowcharts and Pseudo-codes,
implementation of algorithms. Basics of Python Programming:
Features of Python, Writing and executing Python program,
Literal constants, variables and identifiers, Data Types, Input
operation, Comments, Reserved words, Indentation, Operators and
expressions, Expressions in Python.
Programming Design Tool
• Algorithms
• Flowcharts
• Pseudo-codes
• implementation of algorithms.
Algorithms
• Algorithm refers to a set of rules/instructions that step-by-
step define how a work is to be executed in order to get
the expected results.
Algorithm of linear search:
• Start from the leftmost element of arr[] and one by one
compare x with each element of arr[].
• If x matches with an element, return the index.
• If x doesn’t match with any of elements, return -1.
Flowcharts
• Flowcharts graphically represent the flow of a program. There are four
basic shapes used in a flow chart. Each shape has a specific use:
• oval: start / end
• parallelogram: input / output
• rectangle: calculations
• diamond: selection structures
Flowchart Example
Pseudocode
• Pseudo code is a term which is often used in programming and algorithm based
fields. It is a methodology that allows the programmer to represent the
implementation of an algorithm.
• How to write a Pseudo-code?
• Arrange the sequence of tasks and write the pseudocode accordingly.
• Start with the statement of a pseudo code which establishes the main goal or the
aim.
• Example:
• This program will allow the user to check
the number whether it's even or odd.
• Example:
• if "1"
print response
"I am case 1“
•
if "2"
print response
"I am case 2"
What is Python?
Python is a popular programming language. It was created by Guido
van Rossum, and released in 1991.
It is used for:
web development (server-side),
software development,
mathematics,
system scripting.
Features in Python
• Free and Open Source
• Easy to code
• Easy to Read
• Object-Oriented Language
• GUI Programming Support
• High-Level Language
• Easy to Debug
• Python is a Portable language
• Dynamically Typed Language
• Allocating Memory Dynamically
Python Syntax compared to other
programming languages
Python was designed for readability, and has some similarities to the
English language with influence from mathematics.
Python uses new lines to complete a command, as opposed to other
programming languages which often use semicolons or parentheses.
Python relies on indentation, using whitespace, to define scope; such as
the scope of loops, functions and classes. Other programming languages
often use curly-brackets for this purpose.
For Example:
print("Hello, World!")
Python Install
To check if you have python installed on a Windows PC, search
in the start bar for Python or run the following on the Command
Line (cmd.exe):
C:UsersYour Name>python –version
The way to run a python file is like this on the command line:
C:UsersYour Name>python helloworld.py
Program save as : helloworld.py
print("Hello, World!")
Python Program
Python Indentation
Indentation refers to the spaces at the beginning of a code
line.
Where in other programming languages the indentation in
code is for readability only, the indentation in Python is very
important.
Python uses indentation to indicate a block of code.
For Ex.
if 5 > 2:
print("Five is greater than two!")
if 5 > 2:
print("Five is greater than two!")
Python Keywords
• Python has a set of keywords that are reserved words that
cannot be used as variable names, function names, or any other
identifiers:
• Keyword Description
• And A logical operator
• As To create an alias
• Assert For debugging
• Break To break out of a loop
• Class To define a class
• Continue To continue to the next iteration of a loop
• Def To define a function
Comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #, and Python will render the rest of the line as a comment:
Example
1.Comments in Python:
#This is a comment.
print("Hello, World!")
2.Multiline Comments
To add a multiline comment you could insert a # for each line:
Example
#This is a comment
#written in
#more than just one line
print("Hello, World!")
Python Variables
Variables
• Variables are containers for storing data values.
• Creating Variables
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a
value to it.
Example:
x = 5
y = "John"
print(x)
print(y)
Casting
If you want to specify the data type of a variable, this can be
done with casting.
Example:
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Type()
Get the Type
You can get the data type of a variable with
the type() function.
Example:
x = 5
y = "John"
print(type(x))
print(type(y))
Single or Double Quotes?
• String variables can be declared either by using single or double quotes:
Example
x = "John"
# is the same as
x = 'John‘
Case-Sensitive
• Variable names are case-sensitive.
Example
• This will create two variables:
a = 4
A = "Sally"
#A will not overwrite a
• Example
Illegal variable names:
2myvar = "John"
my-var = "John"
my var = "John"
Legal variable names:
• myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Many Values to Multiple Variables
• Python allows you to assign values to multiple variables in one
line:
Example:
• x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
One Value to Multiple Variables
• And you can assign the same value to multiple variables in one line:
Example
• x = y = z = "Orange"
print(x)
print(y)
print(z)
Unpack a Collection
If you have a collection of values in a list, tuple etc. Python
allows you to extract the values into variables. This is
called unpacking.
Example
Unpack a list:
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Global Variables
• Variables that are created outside of a function (as in all of the
examples above) are known as global variables.
• Global variables can be used by everyone, both inside of
functions and outside.
• Example
• Create a variable outside of a function, and use it inside the
function
• x = "awesome"
def myfunc():
print("Python is " + x)
myfunc()
• Create a variable inside a function, with the same name as
the global variable
• x = "awesome"
def myfunc():
x = "fantastic"
print("Python is " + x)
myfunc()
print("Python is " + x)
• If you use the global keyword, the variable belongs to the
global scope:
• def myfunc():
global x
x = "fantastic"
myfunc()
print("Python is " + x)
Python Data Types
Built-in Data Types
• In programming, data type is an important concept.
• Variables can store data of different types, and different types can do
different things.
• Python has the following data types built-in by default, in these categories:
• Text Type:str
• Numeric Types:int, float, complex
• Sequence Types:list, tuple, range
• Mapping Type:dict
• Set Types:set, frozenset
• Boolean Type:bool
• Binary Types:bytes, bytearray, memoryview
• None Type:NoneType
Examples
Example Data Type
• x = "Hello World “ str
• x = 20 int
• x = 20.5 float
• x = 1j complex
• x = ["apple", "banana", "cherry"] list
• x = ("apple", "banana", "cherry") tuple
• x = range(6) range
• x = {"name" : "John", "age" : 36} dict
• x = {"apple", "banana", "cherry"} set
• x = True bool
• x = b"Hello“ bytes
Random Number
• Python does not have a random() function to make a random
number, but Python has a built-in module called random that
can be used to make random numbers:
• Example
Import the random module, and display a random number
between 1 and 9:
import random
print(random.randrange(1, 10))
Python Operators
• Operators are used to perform operations on variables and
values.
• In the example below, we use the + operator to add together
two values:
• Example
print(10 + 5)
Python divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
Python Arithmetic Operators
Operator Name Example
+ Addition x + y
- Subtraction x – y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y
Python Assignment Operators
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x – 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
Python Comparison Operators
Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Python Logical Operators
Operator Description Example
and Returns True if both statements are true x < 5 and x<10
or Returns True if one of the statements is true x < 5 or x < 4
not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
Python Identity Operators
• Operator Description Example
is Returns True if both variables are the same object x is y
is not Returns True if both variables are not the same object x is not y
Python Membership Operators
Operator Description Example
in Returns True if a sequence with the specified
value is present in the object x in y
not in Returns True if a sequence with the specified
value is not present in the object x not in y
Python Bitwise Operators
Operator Name Description Example
• & AND Sets each bit to 1 if both bits are 1 x & y
• | OR Sets each bit to 1 if one of two bits is 1 x | y
• ^ XOR Sets each bit to 1 if only one of two bits is 1 x ^y
• ~ NOT Inverts all the bits ~x
• << Zero fill Shift left by pushing
• left shift zeros in from the right and let the leftmost
• bits fall off x << 2
• >> Signed right shift Shift right by pushing copies
• of the leftmost bit in from the left,
• and let the rightmost bits fall off x >> 2

More Related Content

Similar to Basic concept of Python.pptx includes design tool, identifier, variables.

Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptxYusuf Ayuba
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advancedgranjith6
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python ProgrammingManishJha237
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : PythonRaghu Kumar
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problemsRavikiran708913
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptxIoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptxafsheenfaiq2
 

Similar to Basic concept of Python.pptx includes design tool, identifier, variables. (20)

unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptx
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advanced
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Unit -1 CAP.pptx
Unit -1 CAP.pptxUnit -1 CAP.pptx
Unit -1 CAP.pptx
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python ppt
Python pptPython ppt
Python ppt
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Python
PythonPython
Python
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
bhaskars.pptx
bhaskars.pptxbhaskars.pptx
bhaskars.pptx
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptxIoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptx
 

Recently uploaded

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 

Recently uploaded (20)

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 

Basic concept of Python.pptx includes design tool, identifier, variables.

  • 1. Python Programming Design Tools: Algorithms, Flowcharts and Pseudo-codes, implementation of algorithms. Basics of Python Programming: Features of Python, Writing and executing Python program, Literal constants, variables and identifiers, Data Types, Input operation, Comments, Reserved words, Indentation, Operators and expressions, Expressions in Python.
  • 2. Programming Design Tool • Algorithms • Flowcharts • Pseudo-codes • implementation of algorithms.
  • 3. Algorithms • Algorithm refers to a set of rules/instructions that step-by- step define how a work is to be executed in order to get the expected results. Algorithm of linear search: • Start from the leftmost element of arr[] and one by one compare x with each element of arr[]. • If x matches with an element, return the index. • If x doesn’t match with any of elements, return -1.
  • 4. Flowcharts • Flowcharts graphically represent the flow of a program. There are four basic shapes used in a flow chart. Each shape has a specific use: • oval: start / end • parallelogram: input / output • rectangle: calculations • diamond: selection structures
  • 6. Pseudocode • Pseudo code is a term which is often used in programming and algorithm based fields. It is a methodology that allows the programmer to represent the implementation of an algorithm. • How to write a Pseudo-code? • Arrange the sequence of tasks and write the pseudocode accordingly. • Start with the statement of a pseudo code which establishes the main goal or the aim. • Example: • This program will allow the user to check the number whether it's even or odd. • Example: • if "1" print response "I am case 1“ • if "2" print response "I am case 2"
  • 7. What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side), software development, mathematics, system scripting.
  • 8. Features in Python • Free and Open Source • Easy to code • Easy to Read • Object-Oriented Language • GUI Programming Support • High-Level Language • Easy to Debug • Python is a Portable language • Dynamically Typed Language • Allocating Memory Dynamically
  • 9. Python Syntax compared to other programming languages Python was designed for readability, and has some similarities to the English language with influence from mathematics. Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose. For Example: print("Hello, World!")
  • 10. Python Install To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): C:UsersYour Name>python –version The way to run a python file is like this on the command line: C:UsersYour Name>python helloworld.py Program save as : helloworld.py print("Hello, World!")
  • 11. Python Program Python Indentation Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code. For Ex. if 5 > 2: print("Five is greater than two!") if 5 > 2: print("Five is greater than two!")
  • 12. Python Keywords • Python has a set of keywords that are reserved words that cannot be used as variable names, function names, or any other identifiers: • Keyword Description • And A logical operator • As To create an alias • Assert For debugging • Break To break out of a loop • Class To define a class • Continue To continue to the next iteration of a loop • Def To define a function
  • 13. Comments Python has commenting capability for the purpose of in-code documentation. Comments start with a #, and Python will render the rest of the line as a comment: Example 1.Comments in Python: #This is a comment. print("Hello, World!") 2.Multiline Comments To add a multiline comment you could insert a # for each line: Example #This is a comment #written in #more than just one line print("Hello, World!")
  • 14. Python Variables Variables • Variables are containers for storing data values. • Creating Variables • Python has no command for declaring a variable. • A variable is created the moment you first assign a value to it. Example: x = 5 y = "John" print(x) print(y)
  • 15. Casting If you want to specify the data type of a variable, this can be done with casting. Example: x = str(3) # x will be '3' y = int(3) # y will be 3 z = float(3) # z will be 3.0
  • 16. Type() Get the Type You can get the data type of a variable with the type() function. Example: x = 5 y = "John" print(type(x)) print(type(y))
  • 17. Single or Double Quotes? • String variables can be declared either by using single or double quotes: Example x = "John" # is the same as x = 'John‘ Case-Sensitive • Variable names are case-sensitive. Example • This will create two variables: a = 4 A = "Sally" #A will not overwrite a
  • 18. • Example Illegal variable names: 2myvar = "John" my-var = "John" my var = "John"
  • 19. Legal variable names: • myvar = "John" my_var = "John" _my_var = "John" myVar = "John" MYVAR = "John" myvar2 = "John"
  • 20. Many Values to Multiple Variables • Python allows you to assign values to multiple variables in one line: Example: • x, y, z = "Orange", "Banana", "Cherry" print(x) print(y) print(z)
  • 21. One Value to Multiple Variables • And you can assign the same value to multiple variables in one line: Example • x = y = z = "Orange" print(x) print(y) print(z)
  • 22. Unpack a Collection If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking. Example Unpack a list: fruits = ["apple", "banana", "cherry"] x, y, z = fruits print(x) print(y) print(z)
  • 23. Global Variables • Variables that are created outside of a function (as in all of the examples above) are known as global variables. • Global variables can be used by everyone, both inside of functions and outside. • Example • Create a variable outside of a function, and use it inside the function • x = "awesome" def myfunc(): print("Python is " + x) myfunc()
  • 24. • Create a variable inside a function, with the same name as the global variable • x = "awesome" def myfunc(): x = "fantastic" print("Python is " + x) myfunc() print("Python is " + x)
  • 25. • If you use the global keyword, the variable belongs to the global scope: • def myfunc(): global x x = "fantastic" myfunc() print("Python is " + x)
  • 26. Python Data Types Built-in Data Types • In programming, data type is an important concept. • Variables can store data of different types, and different types can do different things. • Python has the following data types built-in by default, in these categories: • Text Type:str • Numeric Types:int, float, complex • Sequence Types:list, tuple, range • Mapping Type:dict • Set Types:set, frozenset • Boolean Type:bool • Binary Types:bytes, bytearray, memoryview • None Type:NoneType
  • 27. Examples Example Data Type • x = "Hello World “ str • x = 20 int • x = 20.5 float • x = 1j complex • x = ["apple", "banana", "cherry"] list • x = ("apple", "banana", "cherry") tuple • x = range(6) range • x = {"name" : "John", "age" : 36} dict • x = {"apple", "banana", "cherry"} set • x = True bool • x = b"Hello“ bytes
  • 28. Random Number • Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers: • Example Import the random module, and display a random number between 1 and 9: import random print(random.randrange(1, 10))
  • 29. Python Operators • Operators are used to perform operations on variables and values. • In the example below, we use the + operator to add together two values: • Example print(10 + 5)
  • 30. Python divides the operators in the following groups: • Arithmetic operators • Assignment operators • Comparison operators • Logical operators • Identity operators • Membership operators • Bitwise operators
  • 31. Python Arithmetic Operators Operator Name Example + Addition x + y - Subtraction x – y * Multiplication x * y / Division x / y % Modulus x % y ** Exponentiation x ** y // Floor division x // y
  • 32. Python Assignment Operators Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x – 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 //= x //= 3 x = x // 3 **= x **= 3 x = x ** 3
  • 33. Python Comparison Operators Operator Name Example == Equal x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 34. Python Logical Operators Operator Description Example and Returns True if both statements are true x < 5 and x<10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
  • 35. Python Identity Operators • Operator Description Example is Returns True if both variables are the same object x is y is not Returns True if both variables are not the same object x is not y
  • 36. Python Membership Operators Operator Description Example in Returns True if a sequence with the specified value is present in the object x in y not in Returns True if a sequence with the specified value is not present in the object x not in y
  • 37. Python Bitwise Operators Operator Name Description Example • & AND Sets each bit to 1 if both bits are 1 x & y • | OR Sets each bit to 1 if one of two bits is 1 x | y • ^ XOR Sets each bit to 1 if only one of two bits is 1 x ^y • ~ NOT Inverts all the bits ~x • << Zero fill Shift left by pushing • left shift zeros in from the right and let the leftmost • bits fall off x << 2 • >> Signed right shift Shift right by pushing copies • of the leftmost bit in from the left, • and let the rightmost bits fall off x >> 2