KEMBAR78
Intro to Python | PPT
Introduction to PythonIntroduction to Python
ProgrammingProgramming
Why Python?Why Python?
 Python is what is referred to as an object-oriented programming
language (OOP)
 Python is a general purpose programming language. That means you
can use Python to write code for a number of programming tasks.
◦ Google search engine
◦ Gaming
◦ Processing financial
transactions
◦ Data Analytics
◦ Physical Programming
 Simple
 Less Syntax
 Extensive User Community
 Interpreted
Interpreted?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?What Does It Look Like?
Parts of a Python ProgramParts of a Python Program
Def: Source Code is the program text
entered into an interpreter by the
programmer.
◦ The saved file is referred to as, the source file.
◦ The main file in a python program, called main
◦ Can program on the command prompt
The extension to a python source file is “.py”
◦ Xcel - .xls
◦ Power Point - .ppt
Two main parts to a source file
◦ Modules
◦ Main code
Good programming proclamationsGood 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
ModulesModules
 A module is a python source file that has prewritten
python code.
 These predefined files allow users to utilize code that has
been previously developed.
◦ Don’t have to recreate the wheel, just use the wheel and
improve on the technology.
 math
 time
 Gpiozero
 Os
 Code: Importing modules
 import module_name
 from module_name import class_name
ExpressionsExpressions
• A programming expression is a
combination of symbols to represent a
value.
• One side of an equation
• Ex.
• 5+7
• False
• print()
• led.on()
Printing a Line of TextPrinting a Line of Text
print(“ “)
Anything placed inside the quotes will be printed on the screen
upon execution of the print command.
Manipulating TimeManipulating Time
The time module is a popular module which
provides functions for working with times and
converting between them.
◦ sleep
◦ local time
◦ epoch time
Code:
◦ Importing time module
 import time
◦ Using time functions
 time.sleep(#)
 time.localtime(time.time())
Manipulating LED’sManipulating LED’s
 The Raspberry Pi comes with a library RPi.GPIO that allow
the manipulation of GPIO pins: s
◦ Setup pins as inputs or outputs
◦ Read inputs
◦ Set output levels
 However, gpiozero is a wrapper library that is built on top
of RPi.GPIO to provide a simpler interface to manipulate
the pins.
 Code:
◦ Importing gpiozero module
 import gpiozero
◦ Using led functions and objects
 LED(pin#).on()
 LED(pin#).off()
 LED(pin#).blink()
CheckpointCheckpoint
1. What is an IDE?
2. What is a comment and its importance?
3. How is white space used in
programming?
4. What are modules?
5. Name 2 modules

Intro to Python

  • 1.
    Introduction to PythonIntroductionto Python ProgrammingProgramming
  • 2.
    Why Python?Why Python? Python is what is referred to as an object-oriented programming language (OOP)  Python is a general purpose programming language. That means you can use Python to write code for a number of programming tasks. ◦ Google search engine ◦ Gaming ◦ Processing financial transactions ◦ Data Analytics ◦ Physical Programming  Simple  Less Syntax  Extensive User Community  Interpreted
  • 3.
    Interpreted?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 ItLook Like?What Does It Look Like?
  • 5.
    Parts of aPython ProgramParts of a Python Program Def: Source Code is the program text entered into an interpreter by the programmer. ◦ The saved file is referred to as, the source file. ◦ The main file in a python program, called main ◦ Can program on the command prompt The extension to a python source file is “.py” ◦ Xcel - .xls ◦ Power Point - .ppt Two main parts to a source file ◦ Modules ◦ Main code
  • 6.
    Good programming proclamationsGoodprogramming 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
  • 7.
    ModulesModules  A moduleis a python source file that has prewritten python code.  These predefined files allow users to utilize code that has been previously developed. ◦ Don’t have to recreate the wheel, just use the wheel and improve on the technology.  math  time  Gpiozero  Os  Code: Importing modules  import module_name  from module_name import class_name
  • 8.
    ExpressionsExpressions • A programmingexpression is a combination of symbols to represent a value. • One side of an equation • Ex. • 5+7 • False • print() • led.on()
  • 9.
    Printing a Lineof TextPrinting a Line of Text print(“ “) Anything placed inside the quotes will be printed on the screen upon execution of the print command.
  • 10.
    Manipulating TimeManipulating Time Thetime module is a popular module which provides functions for working with times and converting between them. ◦ sleep ◦ local time ◦ epoch time Code: ◦ Importing time module  import time ◦ Using time functions  time.sleep(#)  time.localtime(time.time())
  • 11.
    Manipulating LED’sManipulating LED’s The Raspberry Pi comes with a library RPi.GPIO that allow the manipulation of GPIO pins: s ◦ Setup pins as inputs or outputs ◦ Read inputs ◦ Set output levels  However, gpiozero is a wrapper library that is built on top of RPi.GPIO to provide a simpler interface to manipulate the pins.  Code: ◦ Importing gpiozero module  import gpiozero ◦ Using led functions and objects  LED(pin#).on()  LED(pin#).off()  LED(pin#).blink()
  • 12.
    CheckpointCheckpoint 1. What isan IDE? 2. What is a comment and its importance? 3. How is white space used in programming? 4. What are modules? 5. Name 2 modules

Editor's Notes

  • #5 Common elements in programming languages: Key Words Programmer-Defined Identifiers Operators Punctuation Syntax
  • #9 Where have you heard of expressions before? Math class and what were they