Instagram: ECOsummaries
DM me for 20% discount!
Summary for the course ''Programming Python / Datacamp''. This summary was written in order to study for the midterm as well as for the final. Everything you need to know is available in this summary.
Advice: this summary alone will not be enough, th...
Simple calculations.
E.g. print(7 + 10), , 45 * 234, print(346 * 345)
Harder calculations.
E.g. 4 ** 2 = 16, 18 % 7 = 4 → (2 rest 4)
Comments (use #)
E.g. # division, # addition
Creating variable
E.g. x = 5, savings = 100
Integer (int) = number without a fractional part e.g. 100
Floating (float) = number with a fractional part e.g. 100.5
String (str) = text e.g. “compound” or ‘compound’
Boolean (bool) = True or False e.g. profit = True, profit = False
type(a) = gives the type of a e.g. type(a) = float, type(a) = bool
Pi_float = float(pi_string) → converting from string to float
Pi_bool = bool(pi_float) → converting from float to bool
Python lists
Lists
E.g. kitchen = a, hall = b etc. → areas = [a, b, c, d]
Strings in lists
E.g. liv = 10, bat = 20 → areas = [‘living room’, liv, ‘bathroom’, bat] → living room 10, bathroom
20
Sublists
E.g. house = [[‘hallway’, hall], [‘kitchen’, kit], [‘living room’, liv]]
house[1] gives [‘kitchen’, kit], since it is 1 department of the big list house.
! always use a comma if it’s not the end !
indexing
e.g. fam = [‘liz, 1.73, ‘emma’, 1.68, ‘mom’ , 1.71]
fam[4] = ‘mom’ ! zero indexing !
fam [-1] = 1.71 ! negative indexing !
Slicing
e.g. fam = [‘liz, 1.73, ‘emma’, 1.68, ‘mom’ , 1.71]
fam[3:5] = [1.68, ‘mom’] ! 3 is inclusive, but 5 is exclusive !
fam[:3] = [‘liz, 1.73, ‘emma’, 1.68]
fam[4:] = [‘mom, 1.71]
if house[-1] = [‘bathroom’, 9.5] → house[-1][1] = [9.5]
list manipulation - changing
e.g. fam = [‘liz, 1.73, ‘emma’, 1.68, ‘mom’ , 1.71]
fam[1] = 1.75, the list will change accordingly
fam[0:2] = [‘lisa’, 1.75], the list will change accordingly
list manipulation – adding
fam + [‘me’, 1.87] it will be added to the list
2
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 ecosummaries. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.30. You're not tied to anything after your purchase.