Zen of Python

--Originally published at Start in the world of the #TC101

™Tim Peters en el 2004 descubrió la manera perfecta de poder escribir en Python, y sobretodo nos demuestra que puede escribirse en cualquier idioma y esto te ayuda a hacerlo de una forma clara y fácil de entender y comprender el programa.

™Para que se desplieguen estas, tu únicamente debes de escribir “import this” y la magia esta hecha.

z

Leer más en:

https://www.python.org/dev/peps/pep-0020/

http://emnl.me/python-sensei-the-zen-of-python/#more-37069


Use of loops with “while” and loops with “for”

--Originally published at Start in the world of the #TC101

Loops in Think Python

Loops with “for”

Python provides a clean iteration syntax. Note the colon and indentation.

Example

>> for i in range(0, 3):
>>     print(i*2)
0
2
4

Loops with “while”

A While loop permits code to execute repeatedly until a certain condition is met. This is useful if the number of iterations required to complete a task is unknown prior to flow entering the loop.

Syntax

while condition:
    //do something
>> looping_needed = True
>>
>> while looping_needed:
>>     # some operation on data
>>     if condition:
>>          looping_needed = False

Calling & Creating Functions

--Originally published at Py(t)hon

I think is time to start with functions, i’m no experts at this topic so maybe we can learn together, let’s go

First, what is a function? Very simple, is a piece of reusable code that can be call upon whenever you need it. In other words, if you are going to repeat a code several time the best you can do is create a function, so you don’t have to write it all over again and again. Is to make your life easier.

To create a function you have to start with def follow by parenthesis (), inside this parenthesis goes the parameters necessary, if needed of course, after the parenthesis goes a colon (:) and then to close it, use the return function follow by the value statement, if you don’t want it to return anything, just leave a blank space, the system will take it like None.

Here is my example:

def1.png

In this example I can call whenever I want the areacuadro function, that will be all:) #Pug#Tec#TC101#Functions

Here is a webpage where you can find it better explain link

 

 


Use of comments!

--Originally published at Start in the world of the #TC101

Well…after a long time, I’m going to start publish, and more like that I want to share what I have been learning in the class #TC010 with Ken…lets start!

The comments in Python are notes that you can use when your programs get bigger and more complicated, and this notes help you to know in  natural language what the program is doing and the symbol you use are #.

 

Like in this example:

 


Input = not so difficult

--Originally published at Py(t)hon

Hi again, today we are going to see how to make an input, it is actually not that hard so i think you won’t have any difficulties.

So this is how it goes:

Something = input ( whatever you want to ask)

Then you can go like:

Print = (“This” + Something + “ is very nice”)

Here is one example:

input1

Inputs are not difficult so don’t waste a lot of time with them, focus on more important things, but if you have difficulties you can always ask Ken.


Python’s Types of Data

--Originally published at Py(t)hon

Python has five standard types of data:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionary

The number type data is used to store numerical values, this are created when you assign a value to the object.

var1 = 5

var2= 15

Pythons support four different numerical types:

  • int ( signed integers )
  • long ( long integers, they can also be represented in octal and hexadecimal)
  • float ( floating point real values)
  • complex (complex numbers)

Some examples, for a clearer view:

int long float complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32.3+e18 .876j
-0490 535633629843L -90. -.6545+0J
-0x260 -052318172735L -32.54e100 3e+26J
0x69 -4721885298529L 70.2-E12 4.53e-7j

In the other hand we have the String which are a set of values represented inside a quotation mark.  Python allows either pairs of single or double. Subsets of the string can be made by a slice operator ([] and [:]). Every set starts at 0 to -1. You can include the sing (+) to add something else and the (*) to repeat that string a number of times. Here is an example for a better understanding:

string1

The next type is the list, where you will find items separated by commas and inside brackets, you can access to this list like the string but the difference is that it will appear the complete list of the place you chose, not only a letter or a value; also like the previous you can add something with the (+) and repeat the list with the (*) and example:

list1

The tuples are very similar to the lists, but the main difference is that the tuples are enclosed between parenthesis and not brackets as the list, and another main point is that

tuple 1
dictionarie1
Continue reading "Python’s Types of Data"

Zen of Python

--Originally published at Py(t)hon

The Pythoneer Tim Peters channeled the benevolent dictator of life guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.

1- Beautiful is better than ugly.
2- Explicit is better than implicit.
3- Simple is better than complex.
4- Complex is better than complicated.
5- Flat is better than nested.
6- Sparse is better than dense.
7- Readability counts.
8- Special cases aren't special enough to break the rules.
9- Although practicality beats purity.
10- Errors should never pass silently.
11- Unless explicitly silenced.
12- In the face of ambiguity, refuse the temptation to guess.
13- There should be one-- and preferably only one --obvious way to do it.
14- Although that way may not be obvious at first unless you're Dutch.
15- Now is better than never.
16- Although never is often better than *right* now.
17- If the implementation is hard to explain, it's a bad idea.
18- If the implementation is easy to explain, it may be a good idea.
19- Namespaces are one honking great idea -- let's do more of those!

You can find this information in: https://www.python.org/dev/peps/pep-0020/

#Zen#Pug#TC101#Tec#Python


#Comments??

--Originally published at Py(t)hon

8ici2juxmrk88
Image via GIPHY

Continuing with Python, it’s time to learn about the comments, which are no more than pieces of codes that are not supposed to be run by the interpreter. This comments help the programmer understand better the code, and also if for any reason you get confuse, you can find your path once again by reading the comments.

For us to start a comment in Python there is only one requirement, to star with a number sing #.comentarios 1

As you can see, the comments where not run, only the function “print”. There is another use for the comments, let say you have a piece of the code that you don’t want the interpreter to run, but also you don’t want to erase it. What to do? The answer is simple, just turn it into a comment.

comentarios 2 comentarios3

For the people that is using eclipse to program, there are certain thing you can do to make your life easier, and your programing, on the top left corner in there is the option “Source” in there you will find two buttons one is Comment and the other one Uncomment, by selecting the piece of code and clicking on of these buttons you will be able to turn that piece of code into a comment or make that comment a piece of code again?.

comentarios4

Here is the video that help me understand comments …

#TC101#Pug#Comments#Nomoreplease#ISC#Tec