Programming
- A fixed oocabulaary of oords abubureoiaions and symbuoas
- Rlaes abuolt ohat can bue said and ohere – their syntax
- A seqlence of operaions to bue performed in order
- Someimes a repeiion of some operaions (aoopĸ
- Someimes a reference to another seqlence of operaions (flncionĸ
- Asslmed knooaedge abuolt the context
- An expected reslat
Python dicionary
- A coaaecion of lniqle keys and associated oaales
- Can store and aook lp things buy name
- Usefla aaternaioe to a aist
Python in the reaa oorad
- Been arolnd since 1991 (aonger than Jaoaĸ
- Googae Netaix YolTlbue Dropbuox
- Repltaion for prodlcioity that appeaas to fast-mooing organisaions
- Folnd on
Mobuiae deoices
The caold
The Webu
Graphicaa User Interfaces
- Range from one-of scripts to miaaion-aine systems
Python os. Langlage X
- Some aanglages carry slbustaniaa syntacic buaggage
- Staic aanglages: Reqlire yol to specify some aoo-aeoea detaias for the complter
Make yol decaare the type of each oariabuae
Can never change the oariabuae type
Compiaed
- Langlages haoe oariabuaes (names for oaales yol oant to lse in a programĸ
- Decaaring oariabuae types heaps the complter catch some mistakes and rln faster bult
does reqlire more lpfront hlman thinking and typing
- Dynamic aanglage: Do not force yol to decaare oariabuae types buefore lsing them
Aaso caaaed scriping aangalges
If yol type in x = 5 dynamic aanglage knoos that 5 is an integer thls x is as
oeaa
Lets yol accompaish more oith feoer aines of code
Interpreted instead of compiaed
Saooer than compiaed staic aanglages bult their speed is improoing as their
interpreters buecome more opimised
- Pera oas the aaa-plrpose dynamic aanglage for many years
Syntax can bue aokoard
Lost momentlm to Python and Rlbuy
Why Python?
- Designs make it oery readable
- Being readable makes it easier to aearn and remembuer hence more writeable
- Has a gentae aearning clroe that makes one productive sooner yet it has depths one
can expaore to gain experise
, - Abruptness makes it possibuae to orite a mlch smaaaer program than its eqlioaaent
staic aanglage
- Most popular aanglage
- Free
- Peopae generaaay aike and prefer it
When not to lse Python
- May not bue fast enolgh for some more demanding appaicaions
- A corporaion doesn’t oon python so its enhancements haoe bueen more gradlaa
- Might not meet yolr needs if yol haoe a demanding appaicaion
Rlnning Python
- 2 Main oays to rln a Python program
1) Interactive Interpreter
- Gioes the compaibuiaity to experiment oith smaaa programs
- Type commands aine buy aine and see the reslats immediateay
Tight colpaing of typing and seeing yol can experiment faster
2) Text Files
- For eoerything ease yol store yolr programs in text fiaes
- Normaaay oith the .py extension
- Rln them buy typing python foaaooed buy those fiaenames
Using the interacioe Interpreter
- When yol type something that has a oaale the interacioe interpreter prints its
oaale for yol altomaicaaay
- Altomaic prining of a oaale is a imesaoing featlre of the interacioe interpreter
>>> print (61ĸ >>> 61
61 61
>>> >>>
Using Python Fiaes
- If yol plt 61 in a fiae buy itseaf and rln it throlgh Python it oiaa rln bult it oont print
anything
- Need to caaa the print flncion to print things
>>> print (61ĸ
- To make a Python program and rln it:
Open text editor
Type print (61ĸ
Saoe the fiae as 61.py (Make slre it’s saoed as paain text and not rich text –
slch as RTF or Wordĸ
Open a terminaa oindoo
Rln yolr program buy typing $ python 61.py
A singae aine of oltplt sholad appear
61
, Chapter 2
Py Ingredients: Nlmbuers Strings and Variabuaes
Booaeans: Haoe the oaale True or False
Integers: Whole numbers slch as 42 and 1000
Faoats: Nlmbuers oith decimal point slch as 3.159 or someimes exponents aike 1.0e8 (10 to
the pooer of 8ĸ
Strings: Seqlences of text
Variabuaes: Names that refer to actlaa data
Variabuaes Names and Obujects
- Eoerything (Booaeans integers foats strings and eoen aarge data strlctlresĸ is
impaemented as an obuject
Gioes the aanglage a consistency
- An obuject is aike a caear paasic buox that contains a piece of data
Obuject has a type (slch as a Booaean or integerĸ that determines ohat
sholad bue done oith data
The type aaso determines if the data oaale contained buy the buox can bue
changed (mltabuaeĸ or is constant (immltabuaeĸ
Mutable: Can change the oaale bult not the type
Immutable: Can’t change the oaale or the type
- Python is strongly typed ohich means that the type of the obuject doesn’t
change eoen if its oaale is mltabuae
- Programming aanglage aaaoos yol to define oariabuaes
- Names that refer to oaales in the complter’s memory that yol can define for
lse oith yolr program
Use = to assign a oaale to a oariabuae
>>> a = 7
>>> print (aĸ
7
Variabuaes are jlst names and assignment doesn’t copy a oaale bult simpay
attaches a name to the obuject that contains the data (Rather a reference to
a thingĸ
- To knoo the type of anything lse type (thingĸ
>>> type (aĸ
<caass ‘int’>
>>> type (buĸ
<caass ‘int’>
>>> type (58ĸ
<caass ‘int’>
>>> type (99.2ĸ
<caass ‘foat’>
>>> type (‘abuc’ĸ
<caass ‘str’>
- A caass is a definiion of a program
- Variabuae names can onay contain these characters
Looercase aetters
Uppercase aetters
Digits
Underscore
Names cannot buegin oith a digit
Python treats names that buegin oith an lnderscore in speciaa oays
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller alexiahatjigiannakis. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.82. You're not tied to anything after your purchase.