Python Crash Course Lists & Notes! #2

Hi Everyone, 

These are just the notes I have been taking whilst learning Python I will apologise in advance as they are a bit of a mess due to my word license running out! So I am using this as a sort of substitute for a notes dump. 

Data Types -
Int - Whole number.
Float - Decimal Number. 
Constant - written in all caps. Constants never change.

Methods - 
f = To insert a variable’s value into a string, place the letter f immediately
before the opening quotation mark.
.rstrip - takes whitespace away from right side.
.lstrip - takes whitespace away from left side.
.strip - takes whitespace away.
.upper - sets strings to capital text. 
.lower - sets strings to lower text.
.title = puts makes each word first letter capital 
.append - for lists
.insert - for lists
.pop - for lists. Takes item specified by index and prints it (or "pops" it) example - .pop(0) will print first value.
.remove - used for lists. Removes specified index value. 
\t = tab
\n = new line 

Lists [] - A list is a collection of items in a particular order. You can make a list that
includes the letters of the alphabet, the digits from 0–9, or the names of
all the people in your family. [] brackets indicate a list. Lists start at 0. Can use -1 to access the last number in the list the index -2 returns the second item from the end of the list,
the index -3 returns the third item from the end, and so forth.

Using List - 
dogs = ["Akita", "Collie", "Boarder"]
message = "My Favourite dog is"
print(f"{message.title()} {dogs[-1].title()}")
Changing value in list =
dogs[0] = "Sausage Dog"
This will change the value of Akita to "Sausage dog" 

Appending List -
dogs.append("Terrier")
This will add terrier into the end of the list.

Delete value from list - 
del dogs[0] 
this will delete the first value from the list and the value can no longer be used.

Comments

  1. You wrote this post very carefully.Learning Python for Data Analysis and Visualization The amount of information is stunning and also a gainful article for us. Keep sharing this kind of articles, Thank you.

    ReplyDelete

Post a Comment

Popular posts from this blog

Python Crash Course Chapter 1-2! #1

I PASSED! Cisco CCNA 200-301! Experience & Where I'm going from here!

Python Notes #6 Functions