Lists and Tuples

--Originally published at Hackerman's house

chema

I review this topic with my good friend Sebastian Cedeño, we read a lot about this topic and made this really cool post. So bad that I had to finish it and upload it, so im doing this really late in friday night. There is a little bit of regreat in this words, but i’m also happy that I could finish this partial just as planned. Also check out Cheba’s blog: https://chebasquared.wordpress.com/

Lists and Tuples are sequenced types of data so called because they behave like a sequence.  This type of data is different than the numeric data because they are made of smaller elements that are put together. The elements that are inside a List or a Tuple can be almost any type of data, like a string, a numeric value even another list or tuple.

Define a list is really simple. Its similar to a string just that in this case we dont use ”, we use  square brackets. []

ListExample = [2, “Chema “, 3, “Paco “, (“Perro”, “Gato”)]

A tuple is almost the same as a list, the main difference between this two is that a list can be updated and modified, and a tuple cant be moddified once it has been defined. This means that the original values that are inside a Tuple will be there forever. Also the way that they are defined is a little bit different. While lists use square brackets, Tuples use parenthesis ().

TupleExample = (6, 9, “Clase “, [“Tarde “, “Dr. Strange “])

You can do many things with these type of data, for example you can select a certain element that is inside the list or tuple. In the following example you will get the first element on the list, the first element has a

Continue reading "Lists and Tuples"

I HAVE NO IDEA OF WHAT THIS IS…

--Originally published at Coding The Future

Picture by Syd Wachs.

Yup... I really don't. Thankfully I was able to find it on my dictionary, and I can now explain to you what a dictionary in Python is.

Remember lists and tuples? Dictionaries are very similar, only that this time, indexes have names, and can hold several types of information within one variable. Little confused? So was I... Here's an example.

Declaring Dictionaries

Let's say I wanted to create a dictionary with all of my personal information, instead of having a single variable for each thing. This is what it would look like:

myInfo = {'Name': 'Emanuel', 'Age': 18, 'University': 'Tec de Monterrey'}

As you can see, declaring a dictionary is quite easy. All I did was to begin with the dictionary's name, and then I assigned values inside of curly brackets. Inside of the brackets, I start by naming the first index Name, and declared the value after the colon. The second index comes after the coma, and if you pay close attention, you'll notice it is not a string, like the first and last index. That's because dictionaries can have several types, unlike lists and tuples.

Therefore, if I wanted to print my name from the dictionary, here's what I would do:

print(myInfo[Name])

Notice how I use the index name and not its number. That's what makes dictionaries different from lists and tuples.

Dictionaries can come in handy when you are dealing with information that can be identified with a name easier than with a number. If you want to learn more ways of how you can use them, be sure to check this tutorial by TutorialsPoint and this one Learn Python The Hard Way –they both really helped me!

That's it for today! Stay tuned for exiting content about bots coming up next Continue reading "I HAVE NO IDEA OF WHAT THIS IS…"

TUPLE UP! – Diving deeper into Lists and Tuples

--Originally published at Coding The Future

Picture by Ed.ward

Greetings everyone! Time to tuple-up! Or is it bucle-up? Who cares... Just make sure to fasten your seatbelt because we are about to begin a journey!

Today, we'll be discussing two very simple yet very powerful types in Python: Lists and Tuples. You may have heard of arrays in other programming languages, but in Python, we have lists and tuples instead, which are in fact, very similar to them.

Let's begging by quickly defining what a list or tuple is. A list is a variable that can store several values, just like it's name suggests. For example, a list of all of your friends' names. A tuple, on the other hand, is a constant that can hold several values, and obviously it remains unchanged throughout the program. For example, a tuple with the months of the year. Let us begin.

Lists

Declaring a new list is quite simple. All you have to do is type the name of the list, followed by the values you would like to assign inside of square brackets. Take a look:

myFriends = ['Daniela', 'Diego', 'Christian', 'Jillian']
myLuckyNumbers = [2, 3, 7, 13, 10, 15]

As you can see above, I declared two lists. The first one, a list that stores strings, and the second one, stores integers. As you may have intuited from the example, you cannot store different data types in the same list.

Each item is stored in an index number of the list, starting from 0. So if I had to chart the second list for example, it would look something like this:

Index Value Stored
0 2
1 3
2 7
3 13
4 10
5 15

Consequently, if you need to work with a specific value stored in n index, you would simply call Continue reading "TUPLE UP! – Diving deeper into Lists and Tuples"

Lists & Tuples

--Originally published at Python & pugs

This is a very easy topic and I’ll explain it in a very easy way.

To identify a list and a tuple just look at this example:

liststuples

A tuple can be write withouth the “[” “]”, and also you can use “(” “)”, so it is the same if you write:
x = 1,2,3,4

or

x = (1,2,3,4)

But for lists you’ll need to write it with “[” “]”

y = [5,6,7,8]

And now, you can use these lists and tuples in several ways, but I’m going to show the easiest way to use them, and we are going to ask for a number in a certain for position, and for this you need to know that python starts counting from 0.

liststuples2liststuples3


List/Tuples

--Originally published at Programming

Introduction

Don’t worry. This topic is not going to be as hard and abstract as the last one, today we are going to go back to something simple. We are going to learn about variables! But not like the normal kind of variables… Let’s get started. A variable is a reserved space of memory that stores information, which can be changed at any time. If you want to store a long list of information that doesn’t change over time or a long list of information that changes over time. How can you do it? Well here are the answers to your problems:

Lists

Just like its name, it contains a list of elements. Each one of the elements is numbered (has an index), starting from zero. You are allowed to remove items and add values to the list by using their position index on the list. Basically lists are one of the most important concepts in Python that you’ll be using a lot. Think of it as a variable on steroids.

1.png

Tuples

Tuples are just like lists, the only difference is that you can’t change their values. The values that you give the tuple the first time are the values the tuple is going to have for the rest of the program’s life. Just like the list, each value is numbered starting from 0. Unlike lists, the tuples must have parentheses surrounding their values instead of brackets. 2.png

*Note: The list examples were taken from a YouTube video https://youtu.be/1yUn-ydsgKk?list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_ You should check out his channel.


I AIN’T GOT NO TYPE

--Originally published at Coding The Future

Image via GIPHY

Personally, I am not a rap fan, but again, I am making a reference to a song. This time, No Type by Rae Sremmurd came to mind when thinking about the different types of data you can work with on Python.

Even though we've already been working with them, let's discuss these data types in more detail...

  • Integers: They store a whole numeric value with no decimals, e.g.: 5.
  • Floats: They store a numeric value with decimals, e.g.: 23.43.
  • String: They store a string of characters of any type, e.g.: "Hello". Note that in Python there is no char (character) type. If you wanted to store only one character, use a string of length one. Also, just like it's name suggests, it is a string of characters tied together, so you can access each character using it's position. For example, in "Hello", string[1] is 'e'.
  • Booleans: They store a binary value of true or false. Basically, a variable of this type can only have a value of true or false. The false value can be expressed as 0, and true as any other number. E.g.: userIsMale = false.

Also, there are types in which several items can be stored within one variable. In other programming languages, they are usually called arrays, but in python they are somewhat different.

  • Lists: A list that stores several variables, and can be expansible. They are not limited to just storing one type of data; or in other words, you can store ints, strings, floats, in just one list. E.g.: list = [1, 2, hey, music, 12.34]
  • Tuples: Similar to a list, but static. Once it is declared, it remains fixed. E.g.: tuple = {1, 3, hello}

That's Continue reading "I AIN’T GOT NO TYPE"

I AIN’T GOT NO TYPE

--Originally published at Coding The Future

Image via GIPHY

Personally, I am not a rap fan, but again, I am making a reference to a song. This time, No Type by Rae Sremmurd came to mind when thinking about the different types of data you can work with on Python.

Even though we've already been working with them, let's discuss these data types in more detail...

  • Integers: They store a whole numeric value with no decimals, e.g.: 5.
  • Floats: They store a numeric value with decimals, e.g.: 23.43.
  • String: They store a string of characters of any type, e.g.: "Hello". Note that in Python there is no char (character) type. If you wanted to store only one character, use a string of length one. Also, just like it's name suggests, it is a string of characters tied together, so you can access each character using it's position. For example, in "Hello", string[1] is 'e'.
  • Booleans: They store a binary value of true or false. Basically, a variable of this type can only have a value of true or false. The false value can be expressed as 0, and true as any other number. E.g.: userIsMale = false.

Also, there are types in which several items can be stored within one variable. In other programming languages, they are usually called arrays, but in python they are somewhat different.

  • Lists: A list that stores several variables, and can be expansible. They are not limited to just storing one type of data; or in other words, you can store ints, strings, floats, in just one list. E.g.: list = [1, 2, hey, music, 12.34]
  • Tuples: Similar to a list, but static. Once it is declared, it remains fixed. E.g.: tuple = {1, 3, hello}

That's Continue reading "I AIN’T GOT NO TYPE"