0 ratings0% found this document useful (0 votes) 25 views8 pagesPython Crash Course
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
* Running the Hello world, Peogsan
=> Print (Hello Python world")
Hello Python World
* \Joviables
=
Nowiables ave contatners for sovting data velvet:
Message = “Hello Python Wosld"
Print (message)
Hello Python world
* String
fy string ts 0 sequence of choxacters -
name = Ada hovelace
Print [Link] ©
Print (name: lower t})
ADA WOVELACE fe |
Prd, Lovelace+ Combining ox_concatenstny Strings
=> message = "Hello," , full name. rte C+
Pain (message)
a Numbexs
(Trtegexs”? You can od U2), Subtvact multiply CD,
ond divide (/) integers in python. t
“"
d>>a43 SS sro. >> dSarsty
5 q |
>>>3-2 ans og SSD (atD'Y
4. at = 20
>>>ara sssio ft
G
>>> 3ja lovo000
tS
* What fg a Mist 9
A ist is a collection of items | sheulowr order,
you can make o fist at ele Cine | et of the
alphabet, the digits from O-4. oF name
all tte people. Fn yovr family ia com put ouny ting.
qee wont in a “Rist.
le cables leaxwing |ae Precescing Cements ih a List
bicycles = C trek’, cannondale’, ‘vedline’, ‘specialized ‘]
Csint (bieycles La)
bicycles = ( ‘trek’, ‘cannondale’, ‘vedline’, ‘specialized’
’ Point Lbinydles (0). title ts) Ee
x Index Positions
bicycles = ( ‘trek’, “cannondale’,' redline’, ‘specialized ']
Point Chieycles (LJ)
Psint (biowles (2)
motoreycles- append Udventi’
Print (motorcycles)
(Honde' Lomas, 'Svki! J
[Honde.,’ oman, ' Soou ki, Duesti' |
& Removtn
—_——
———
ded cles C1)
ont [oeeoroyeeS)
(Honds.' Yamada, ' Sozoke]
C Honda,’ Yamaha. j [aes i “|"Loppers
Est owned = moboxeyele - pop Co)
Psiwt Che Liyst moto ele L owned Wace a+ fit
owned title ()+ *_')
The first wotoyye I owned wox a Honda,
* Removing an item by valve
motoreycler = ['Honda’, Yamaha’, ‘Suauki', 'Dueati!)
Print (emotoreycles) i
motoweycles- remove (Ducati)
Print C motpseycles)
Sot
cass = [BMW Audi’, ' Toyste’,' Subaru’)
cars: dost (veverte = True)
Print Ceavs)
L' Toysta’, “Sobmeu', ‘BMW ', hud’)
x Keoping
mogiehau. = C'Alice’, ‘Davia’, ‘Covotiva! ]
for magieian in magicians!
printing Comagicians)
¥ Using Rouge furetion
for valve tr ranges (4,5):
Print (valve)
fow valve tv (1,6):
ent aloe)
z Jeoxwiw
Sere% Sayvores
O Sqpave* C)
@ for wave i vange (4,11):
() Syuaree Value 9
@ Gyvores. append [éyvare)
© Print Ceqpares)
(2,4, 9, We, 2S, 36,44, oY BE, 100)
* Tuple
Dimensions = (200,50)
fox dimencion in Limengions
@sint (dimension)
20°
so
e Tf Stotements
cars = Fovdi", dew’, ‘Cubtsu', toyota’)
for car in cart
© af ow e-"bo
print Ccaw. upper \)
eke: .
ek print Loar tite) Jee]
u
auw
Subtsu
Toyota
Checking whether a value wt not ino list
honned—ueexs= [ Andrew’, 'Grobiw', “Divid']
users = Hoxie
OF user not in banned ucers:
Print (user tHe! ‘ou coun pest a vesponce
ua use)+ Vokn
male
i age>=\B
Print C’ You ave. old enough to vote!
You axe ol enovth to we
* Awusement Posk
TE age ety:
Print ("Your odwiscion cock és $o')
# Dictionary
user 0 =
‘ugewnawe'! “epermi’
‘Earet’ + ‘enrico’,
‘last’! ‘fermi’, Ales bering
toy key valve te veer [Link] ll:
pvint (" \nkeg. i y ¥ey)
Print (“value:" + valve)
fox K, vin user O. tome t)
> ee > Ueolour': ‘green’, “Points's s}
en = Ceolow': ‘ ellow, 'forwts :10}
alen-2= Ceolooe: ‘ved’, Pointe t1S%Aliens = [atien-0, alien-1, alien.2]
for alien tn ations +
Pring alien)
{colour “gveen’, ‘points ‘ Sy
{colours * yellows |, * points "+103
Crenloore': "RAS “potnts"? 1S}
* Lnput function
name> input ("Please enter your nanue: *)
frint (Hello, "enamet “(")
fleace enter your WAmL: Damon
Hello, Damon
» Meigit ~ input Cow tall ove your in inde :”)
Wesg hr = int (height)
€ height S= BL .
crint C* \nYou've tall enough to vide |")
Yow fall are you tm inches
oolve. talk enough to wide |
¥ AWhile Loops
eurveuk numbers
while evrrent. number 22S?
grint Courrent_numbey)
Corrent_nowbev += 4
> pets *( ‘dog! Vent! "deg “atlieh' “ek! vabbit ‘cot ]
print (pets)
While teat! vn
es:
ets. Cet! Jeo:
oo : oa ) @ codes lear wing}
wee wre© Defining a Rnetion
Me Dhoplag «Simple greeting ©"
we Epis a inple gre
Prink L Hel! ee
wert uger 6)
Yello!
=> det make Pir, Ci+topeings):
"Print tte list list of Eoppings
that have been veyretted.””"
Priv Ctoppinys)
make - pizza( pepperoni 7 .
wmake- pizza (‘omushrooms’,'g¥een peppers, ‘extra cheece)
U peppexvout by
(mvehroone’,'g teen peppers’, ‘extra cheece)
pail