fire doesn't scare me

fire doesn't scare me

I learned something new in Python today.

If and when checking for a condition, you need an "and" keyword for example.

Let's say I want to check if someone is in their 20's. I need something a little like this:

if age >= 20 and age < 30

Which is new to me and different from JavaScript - I think. Or maybe I just forgot.

trying to concatenate a string with a float

today I learned that Python doesn't allow you to concatenate a string with a float. whoops... sorry

instead you can do this:

str() this is the string method - that converts any integer or float to a string. And probably other data types too, I guess?

Lists

Lists are basically like arrays, now - aren't they??! Everything looks just about identical about the syntax so far - PHEWPH! Lists, just like arrays, can contain different data types.

.append()

So methods in python are similar to JavaScript. They follow the name of the list (which is an array) and they are preceded by a full stop, then the name of the method, and then the brackets as well. It's just like in JavaScript! 💚

The .append() method adds one new item onto the end of a list!

Plus (+)

OMG WHAT! WE CAN ADD TWO LISTS TOGETHER WITH CONCATENATION! OMG OMG THIS IS CRAZY! WHAT!! So you can only add two lists (as in not other data types) and it doesn't alter the existing list; it has to create a new one.

energy_infrastructure = ["pylons", "wind farms", "substations"]

cool_tech_i_like = ["SQL", "Python", "TypeScript"]

cool_stuff = energy_infrastructure + cool_tech_i_like

print(cool_stuff)

#output: ["pylons", "wind farms", "substations", "SQL", "Python", "TypeScript"]

A Negative Index Selects The Last Item On That List

Wow! Wow what wow that's so cool! I didn't know that!!! So if I go print(energy_infrastructure[-1]) it should output "substations'???!. Yes. It does. This is helpful and this is useful if we do not know how many items are on our list. 

Reassignment In Lists

It seems to be identical to JavaScript. But it is a good refresher as I never had it fully ingrained. So you put the name of the list, index it, and then re-assign the variable, like so:

energy_infrastructure[3] = "hydroelectric dams"

print(energy_infrastructure)

#output: ["pylons", "wind farms", "hydroelectric dams"]

although I am quite sorry for the substations though!



Comments

Popular posts from this blog

Hello World

Yosemite

Two Lines of Thought, Makes Me Wonder What I'm Missing