Python Basic types

--Originally published at angelmendozas

Python has five basic types:

#Numbers

you can put them as:

a = 1 b = 3 or var_1=4 var_2=3 or delete them like (“del var”) or (“del var1[,var2[,var3]]] etc.

Also python supports four numerical types:

int (integers), long (long integers, can also be octal or hexadecimal), float (floating point real values) and complex (complex numbers).Captura de pantalla 2016-08-26 a las 8.07.18 p.m..png

#String

A string’s official definition is: “Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.”

I made several strings, sentences to link one to another and printed them to have fun and made up sentences combined with the strings.

Captura de pantalla 2016-08-29 a las 10.29.17 a.m..png

The results were these (Elizabeth is a random name, don’t worry):

Captura de pantalla 2016-08-29 a las 10.29.07 a.m..png

#List

“Lists are the most versatile of Python’s compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type.” -tutorialspoint.com

I made a basic list with words

Captura de pantalla 2016-08-29 a las 10.50.21 a.m..png

this is the result, it solved the 17×10^-4 and the other values were just put like they were in the list

Captura de pantalla 2016-08-29 a las 10.50.31 a.m..png

#Tuple

Tuples are the same as a list its just that the variables go inside of () instead of []

Captura de pantalla 2016-08-29 a las 11.15.47 a.m..png

Captura de pantalla 2016-08-29 a las 11.16.02 a.m..png

#Dictionary

According to tutorials point: “Python’s dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type,

Captura de pantalla 2016-08-30 a las 10.46.13 a.m..png
Captura de pantalla 2016-08-30 a las 10.45.54 a.m..png
Continue reading "Python Basic types"

ZEN OF PYTHON

--Originally published at angelmendozas

You can get this by typing on your mac terminal “python3” enter and then type “import this”.

The Zen of Python, by Tim Peters:

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren’t special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one– and preferably only one –obvious way to do it.

Although that way may not be obvious at first unless you’re Dutch.

Now is better than never.

Although never is often better than *right* now.

If the implementation is hard to explain, it’s a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea — let’s do more of those!


#COMMENTS

--Originally published at angelmendozas

Comments have two ways to be done, but first, why we put a comment in python?

According to python for beginners:

Comments in Python are used to explain what the code does.

1.The first is by using a hashtag (#) before the comment like:

#SUM

and then you do the sum of x number of values or do whatever you put in the comment.

2.The second way to put a comment is using (“””) before and after the comment and this way you can write a paragraph as if you were in Word.

Resources:

http://www.pythonforbeginners.com/comments/comments-in-python


Basic Ops

--Originally published at angelmendozas

During the weekend I learned several stuff and one of them was to make basic operation on python and they are done like this

Captura de pantalla 2016-08-22 a las 10.15.56 a.m.

This is a very clear example: You put your variables as a, b c or d, depending on how many you want.

Then I introduced some comments to specify which operation was going to be written.

For a sum we know it’s +, subtraction -, multiplication *, exponent **, division / , and for the remainder of a division we use %.

The results are these:

Captura de pantalla 2016-08-22 a las 10.29.36 a.m.

For the first division which is the first zero just put: float and you variable in parenthesis like this:

float(c) / a

and it should give you the decimals which are 0.190327…etc. Because if you just put the division then Python will give you the most basic answer, no decimals, just everything that goes before the dot.


Week 1

--Originally published at angelmendozas

We learned how to do our first “Hello World”, it was great to learn this kind of stuff that little by little get us closer to bigger things, I’m glad we have such an encouraging teacher like Ken, I already feel the force in me like in a Luke Skywalker level, there’s a bunch more to learn through the next weeks and months but I’m looking forward to doing more cool stuff (like hacking the pentagon or something like that, jk) #LOL