SlideShare a Scribd company logo
What is Python?
What is Python?
● Python is a popular high-level programming language used in various
applications
○ Python is an easy language to learn because of its simple syntax
○ Python can be used for simple tasks such as plotting or for more complex tasks like
machine learning
Variables, Objects, and Classes
● A variable is a reference to a value stored in a computer’s memory.
● Variables can be sorted into a variety of categories (or data types) such
as numbers (int/float etc), Boolean values (true/false), and sequences
(strings, lists etc).
● An object is a collection of data from a computer’s memory that can be
manipulated.
○ ALL VARIABLES ARE OBJECTS although some objects can be defined by data
referred to by multiple variables.
○ Methods are the functions used to act on/alter an object’s data. They describe
what your object can “do.”
Variables, Objects, and Classes (cont.)
● A class is a collection of objects
who share the same set of
variables/methods.
○ The definition of the class provides a
blueprint for all the objects within it
(instances).
○ Instances may share the same
variables (color, size, shape, etc.), but
they do NOT share the same values
for each variable (blue/red/pink,
small/large, square/circular etc.)
Instance #1
Color: Pink
Name: Polo
Instance #2
Color: Red
Name: Mini
Instance #3
Color: Blue
Name: Beetle
Basic Syntax Rules
● The name of your variable (myInt etc.) is placed on the left of the “=“ operator.
○ Most variable names are in camel case where the first word begins with a lowercase letter and any subsequent words
are capitalized
○ Variable names may also appear in snake case where all words are lowercase, with underscores between words
● The assignment operator (“=“) sets the variable name equal to the memory location where your value is found.
● The value of your variable (“Hello, World”) is placed on the right of the “=“ operator.
○ The type of this value does NOT need to be stated but its format must abide by a given object type (as shown).
myString = “Hello, World” myInt = 7
myFloat = 7.0
myList = [7, 8, 9] myBoolean = true
Basic Syntax Rules
● Function Syntax
○ def...: indicates that you are defining a new function.
○ function() refers to the name of your function. By convention, this name is typically lowercase and represents a verb/action.
○ a,b refers to parameters (values or variables) that can be used within the statements of your function’s definition (......). If
your function has no parameters, an empty parenthetical () is used.
○ The return statement is an optional statement that will return a value for your function to your original call.
def function(a, b):
......
return a + b
Basic Syntax Rules (cont.)
● Calling a function
○ Call the function by referring to its name (function()) and by placing
any necessary arguments (1, 2) within the parenthesis separated by
commas. myValue = function(1, 2)
○ If you wish, you can set your function call equal to a variable (myValue). The value
returned by the function will be assigned to your variable name.
myValue = function(1, 2)
Common Data Types and Operators
● A data type is a means of classifying a value and determining what operations can
be performed on it. All objects have a data type.
● Operators are symbols used carry out specific functions/computations.
● https://www.youtube.com/watch?v=v5MR5JnKcZI
Input/Output
● Input functions (input()) allow users of a program to place values into
programming code.
○ The parameter for an input function is called a prompt. This is a
string (this can be indicated by “” or ‘’) such as “Enter a number: “
○ The user’s response to the prompt will be returned to the input
statement call as a string. To use this value as any other data type,
it must be converted with another function (int()).
● Print functions (print()) allow programs to output strings to users on a
given interface.
○ The parameter of this function is of any type. All types will
automatically be converted to strings.
xString = input(“Enter a number: “)
x = int(xString)
y=x+2
print(y)
If-else Statements
● If-else statements allow programmers to adapt the function of their
code based on a given condition.
● If a given condition (i.e. x % 2 == 0) is true, then the statements
following the if statement (if) will be executed. If the condition is false,
the statements following the else statement (else) will be executed.
○ The condition is tested using the Boolean operators == (is equal
to), != (is not equal to), and (used to test multiple conditions), and
or (used to test if AT LEAST ONE condition is true).
○ Additionally, else-if statements (elif) can be used to provide
unique coding statements for multiple conditions.
xString = input(“Enter a number: “)
x = int(xString)
if x % 2 == 0:
print(“This is an even number”)
elif x == 0:
print(“This number equals 0”)
else:
print(“This is an odd number”)
For Loops
● For loops perform the same task (iterate) for the number of
times specified by an iterable (something that can be evaluated
repeatedly such as a list, string, or range).
● for defines the for loop
● x is the variable defining the number of times the statements
within the loop (print(myInt)) are executed.
● The range(start, stop, step) function is often used to define x.
○ The starting value is defined by start, the final value is
defined by stop – 1, and the magnitude at which x
changes between loops is defined by step.
● in is a Boolean operator that returns true if the given value (x) is
found within a given list, string, range etc.
myString = input(“Enter a number: “)
myInt = int(myString)
for x in range(0, 5, 1): print(myInt)
While Loops
● While loops are statements that iterate so long as a given
Boolean condition is met.
○ x (the variable determining whether or not the
condition is met) is defined and manipulated
OUTSIDE of the header of the while loop (while)
○ The condition (x < 5) is a statement containing a
Boolean variable.
○ break is a statement used to exit the current
for/while loop.
○ continue is a statement used to reject all
statements in the current for/while loop iteration
and return to the beginning of the loop.
myString = input(“Enter a number: “)
myInt = int(myString)
x = 0
while x < 5:
print(myInt)
x= x +1

More Related Content

Similar to uom-2552-what-is-python-presentation.pptx

Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Python ppt
Python pptPython ppt
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Scala qq
Scala qqScala qq
Scala qq
羽祈 張
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Pointers & functions
Pointers &  functionsPointers &  functions
Pointers & functions
Manjitsing Valvi
 
pure-functional-programming.pdf
pure-functional-programming.pdfpure-functional-programming.pdf
pure-functional-programming.pdf
PuneetChaturvedi23
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5alish sha
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
Yusuf Ayuba
 
Dart workshop
Dart workshopDart workshop
Dart workshop
Vishnu Suresh
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
www.ixxo.io
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 
Teach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with ScalaTeach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with Scala
Damian Jureczko
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
tcsonline1222
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 

Similar to uom-2552-what-is-python-presentation.pptx (20)

Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
Python ppt
Python pptPython ppt
Python ppt
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Scala qq
Scala qqScala qq
Scala qq
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Pointers & functions
Pointers &  functionsPointers &  functions
Pointers & functions
 
pure-functional-programming.pdf
pure-functional-programming.pdfpure-functional-programming.pdf
pure-functional-programming.pdf
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
 
Python programming
Python  programmingPython  programming
Python programming
 
C language presentation
C language presentationC language presentation
C language presentation
 
Teach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with ScalaTeach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with Scala
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 

More from ChetanChauhan203001

PPT SEMINAR -EIA.pptx
 PPT SEMINAR -EIA.pptx PPT SEMINAR -EIA.pptx
PPT SEMINAR -EIA.pptx
ChetanChauhan203001
 
CHETAN SEMINAR PPT HDI.pptx
CHETAN SEMINAR PPT HDI.pptxCHETAN SEMINAR PPT HDI.pptx
CHETAN SEMINAR PPT HDI.pptx
ChetanChauhan203001
 
ASDFGHJ.pptx
ASDFGHJ.pptxASDFGHJ.pptx
ASDFGHJ.pptx
ChetanChauhan203001
 
archana50337.pptx
archana50337.pptxarchana50337.pptx
archana50337.pptx
ChetanChauhan203001
 
Academic Search Engines.pptx
Academic Search Engines.pptxAcademic Search Engines.pptx
Academic Search Engines.pptx
ChetanChauhan203001
 
ppt on ANS.pptx
ppt on ANS.pptxppt on ANS.pptx
ppt on ANS.pptx
ChetanChauhan203001
 
CS1Lesson13-IntroClasses.pptx
CS1Lesson13-IntroClasses.pptxCS1Lesson13-IntroClasses.pptx
CS1Lesson13-IntroClasses.pptx
ChetanChauhan203001
 
consolidation-161105065728.pdf
consolidation-161105065728.pdfconsolidation-161105065728.pdf
consolidation-161105065728.pdf
ChetanChauhan203001
 
Semester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.pptSemester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.ppt
ChetanChauhan203001
 
finalppt.pptx
finalppt.pptxfinalppt.pptx
finalppt.pptx
ChetanChauhan203001
 
Project Presentation 2019-2020.pptx
Project Presentation 2019-2020.pptxProject Presentation 2019-2020.pptx
Project Presentation 2019-2020.pptx
ChetanChauhan203001
 
Presentation on.pptx
Presentation on.pptxPresentation on.pptx
Presentation on.pptx
ChetanChauhan203001
 

More from ChetanChauhan203001 (14)

final.pptx
final.pptxfinal.pptx
final.pptx
 
PPT SEMINAR - Copy.pptx
 PPT SEMINAR - Copy.pptx PPT SEMINAR - Copy.pptx
PPT SEMINAR - Copy.pptx
 
PPT SEMINAR -EIA.pptx
 PPT SEMINAR -EIA.pptx PPT SEMINAR -EIA.pptx
PPT SEMINAR -EIA.pptx
 
CHETAN SEMINAR PPT HDI.pptx
CHETAN SEMINAR PPT HDI.pptxCHETAN SEMINAR PPT HDI.pptx
CHETAN SEMINAR PPT HDI.pptx
 
ASDFGHJ.pptx
ASDFGHJ.pptxASDFGHJ.pptx
ASDFGHJ.pptx
 
archana50337.pptx
archana50337.pptxarchana50337.pptx
archana50337.pptx
 
Academic Search Engines.pptx
Academic Search Engines.pptxAcademic Search Engines.pptx
Academic Search Engines.pptx
 
ppt on ANS.pptx
ppt on ANS.pptxppt on ANS.pptx
ppt on ANS.pptx
 
CS1Lesson13-IntroClasses.pptx
CS1Lesson13-IntroClasses.pptxCS1Lesson13-IntroClasses.pptx
CS1Lesson13-IntroClasses.pptx
 
consolidation-161105065728.pdf
consolidation-161105065728.pdfconsolidation-161105065728.pdf
consolidation-161105065728.pdf
 
Semester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.pptSemester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.ppt
 
finalppt.pptx
finalppt.pptxfinalppt.pptx
finalppt.pptx
 
Project Presentation 2019-2020.pptx
Project Presentation 2019-2020.pptxProject Presentation 2019-2020.pptx
Project Presentation 2019-2020.pptx
 
Presentation on.pptx
Presentation on.pptxPresentation on.pptx
Presentation on.pptx
 

Recently uploaded

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 

Recently uploaded (20)

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 

uom-2552-what-is-python-presentation.pptx

  • 2. What is Python? ● Python is a popular high-level programming language used in various applications ○ Python is an easy language to learn because of its simple syntax ○ Python can be used for simple tasks such as plotting or for more complex tasks like machine learning
  • 3. Variables, Objects, and Classes ● A variable is a reference to a value stored in a computer’s memory. ● Variables can be sorted into a variety of categories (or data types) such as numbers (int/float etc), Boolean values (true/false), and sequences (strings, lists etc). ● An object is a collection of data from a computer’s memory that can be manipulated. ○ ALL VARIABLES ARE OBJECTS although some objects can be defined by data referred to by multiple variables. ○ Methods are the functions used to act on/alter an object’s data. They describe what your object can “do.”
  • 4. Variables, Objects, and Classes (cont.) ● A class is a collection of objects who share the same set of variables/methods. ○ The definition of the class provides a blueprint for all the objects within it (instances). ○ Instances may share the same variables (color, size, shape, etc.), but they do NOT share the same values for each variable (blue/red/pink, small/large, square/circular etc.) Instance #1 Color: Pink Name: Polo Instance #2 Color: Red Name: Mini Instance #3 Color: Blue Name: Beetle
  • 5. Basic Syntax Rules ● The name of your variable (myInt etc.) is placed on the left of the “=“ operator. ○ Most variable names are in camel case where the first word begins with a lowercase letter and any subsequent words are capitalized ○ Variable names may also appear in snake case where all words are lowercase, with underscores between words ● The assignment operator (“=“) sets the variable name equal to the memory location where your value is found. ● The value of your variable (“Hello, World”) is placed on the right of the “=“ operator. ○ The type of this value does NOT need to be stated but its format must abide by a given object type (as shown). myString = “Hello, World” myInt = 7 myFloat = 7.0 myList = [7, 8, 9] myBoolean = true
  • 6. Basic Syntax Rules ● Function Syntax ○ def...: indicates that you are defining a new function. ○ function() refers to the name of your function. By convention, this name is typically lowercase and represents a verb/action. ○ a,b refers to parameters (values or variables) that can be used within the statements of your function’s definition (......). If your function has no parameters, an empty parenthetical () is used. ○ The return statement is an optional statement that will return a value for your function to your original call. def function(a, b): ...... return a + b
  • 7. Basic Syntax Rules (cont.) ● Calling a function ○ Call the function by referring to its name (function()) and by placing any necessary arguments (1, 2) within the parenthesis separated by commas. myValue = function(1, 2) ○ If you wish, you can set your function call equal to a variable (myValue). The value returned by the function will be assigned to your variable name. myValue = function(1, 2)
  • 8. Common Data Types and Operators ● A data type is a means of classifying a value and determining what operations can be performed on it. All objects have a data type. ● Operators are symbols used carry out specific functions/computations. ● https://www.youtube.com/watch?v=v5MR5JnKcZI
  • 9. Input/Output ● Input functions (input()) allow users of a program to place values into programming code. ○ The parameter for an input function is called a prompt. This is a string (this can be indicated by “” or ‘’) such as “Enter a number: “ ○ The user’s response to the prompt will be returned to the input statement call as a string. To use this value as any other data type, it must be converted with another function (int()). ● Print functions (print()) allow programs to output strings to users on a given interface. ○ The parameter of this function is of any type. All types will automatically be converted to strings. xString = input(“Enter a number: “) x = int(xString) y=x+2 print(y)
  • 10. If-else Statements ● If-else statements allow programmers to adapt the function of their code based on a given condition. ● If a given condition (i.e. x % 2 == 0) is true, then the statements following the if statement (if) will be executed. If the condition is false, the statements following the else statement (else) will be executed. ○ The condition is tested using the Boolean operators == (is equal to), != (is not equal to), and (used to test multiple conditions), and or (used to test if AT LEAST ONE condition is true). ○ Additionally, else-if statements (elif) can be used to provide unique coding statements for multiple conditions. xString = input(“Enter a number: “) x = int(xString) if x % 2 == 0: print(“This is an even number”) elif x == 0: print(“This number equals 0”) else: print(“This is an odd number”)
  • 11. For Loops ● For loops perform the same task (iterate) for the number of times specified by an iterable (something that can be evaluated repeatedly such as a list, string, or range). ● for defines the for loop ● x is the variable defining the number of times the statements within the loop (print(myInt)) are executed. ● The range(start, stop, step) function is often used to define x. ○ The starting value is defined by start, the final value is defined by stop – 1, and the magnitude at which x changes between loops is defined by step. ● in is a Boolean operator that returns true if the given value (x) is found within a given list, string, range etc. myString = input(“Enter a number: “) myInt = int(myString) for x in range(0, 5, 1): print(myInt)
  • 12. While Loops ● While loops are statements that iterate so long as a given Boolean condition is met. ○ x (the variable determining whether or not the condition is met) is defined and manipulated OUTSIDE of the header of the while loop (while) ○ The condition (x < 5) is a statement containing a Boolean variable. ○ break is a statement used to exit the current for/while loop. ○ continue is a statement used to reject all statements in the current for/while loop iteration and return to the beginning of the loop. myString = input(“Enter a number: “) myInt = int(myString) x = 0 while x < 5: print(myInt) x= x +1