Harambe and ranges

--Originally published at Python & pugs

There are two ways in which you can use ranges in python:

1st. You’ll just simply write

x = range(10)
print(x)

And it will print all number that goes from 0 to 10.

2nd. You write almost the same thing but:

x = range(0,10,2)
print(x)

This means that the range for x will start in 0, it will end at 10, and its frequency it is of 2.

And it is easy as this.

Never forget Harambe, he was not just a gorilla.


Validated users

--Originally published at Python & pugs

The main points of this topics, it is to use the functions “try”, “except” and “else”, and the propourse of this, is to make our program perfect, meaning that it will no crash. We can the user whatever we want, and as long as he answers right, the program will continue.

This is an example:

yeahbitch

Aaaaaand this is basically the key of validating users, if you want to know more about it, you can check this videos out:


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


This one’s FOR you

--Originally published at Python & pugs

MTI4OTg2NTkwNDQwNjI1NDI2.gifThis post will go straight to the point , so watch out, lads.

For getting started, you’ll need first to state a list for “For

for

From that list you can print the numbers in it, also whenever you print a number, you can print other Strings, but they have to be inside of it too.

Example:

for2

Besides, you can also print numbers in a range you ask for:

for3

Not only integers, you can also use Strings:

for4


Python 3: Back to basics

--Originally published at Python & pugs

In python 3 we have 5 main basic types, which are: Booleans, numbers, integers, floats and fractions; which I’ll explain:

Booleans: Tells us if something is true or false

Numbers: Like the name say this variable let us save numbers

Integers: Only whole numbers (1,2,3,87108)

Floats: Numbers with decimals (1.1, 1.4831,24384.0053)

Fractions: (½, 412/30)

 

 

There are also other types as strings (which are sequences of Unicode characters, or in other words just plain text), lists (It is the most versatile datatype in Python, and like the name says it is a list of data, and this data doesn’t necessarily have to be of the same type.) tuples (tuple is a list, that once it is created it cannot be modified), sets (a set is like an un-ordered bag of unique values) and dictionaries(dictionary is a way to store data just like a list, the difference is that you can use almost everything to search for the data, pretty much like a database which lets you store data and also organize it)

 


Modules and Libraries/Calling Functions

--Originally published at Python & pugs

library.gif

Python 3 have so many libraries that you can use when you need them, and you just need to call for them in your program, and in this post I’ll give an example with “math” because is the easiest one (lol).

To make use of the math library you just need to “call” for it:
libraries
So the only to do here is to import the library you want to use, the print whatever you want of the library.
In here you can find all the libraries Python 3 can offer you:
https://docs.python.org/3/library/

but-wait

<THE CREATION OF YOUR OWN PEYOTE (Library)>

To create your own library, you need to make another file where you are going to create a function.

librariesfunction

Now that you have this function, you’ll import it to another file where it is going to run with the number you assign to x.

librariesfunction

And now you made two mastery topics in one!

snoop-dogg-gggggga721eb54a9-290x595x58.gif