Basic Output (Print)

--Originally published at Programming Fundaments

One type of basic output for Python 3 y the orint function. This one is simple, just use the print command to print the result create an output for the program. Example:

>>> print(42)
42
>>>

For the command print to work you must have the values inside “(“” )” and with that you can print your values. You can also print severa values at a time by simply separating the with a coma, all inside the parenthesis

Moren information at: http://www.python-course.eu/python3_print.php


Basic data types

--Originally published at Programming Fundaments

Python has 3 standart data types: Numbers, Strings and Lists

Number Data:

Number data types store numeric information (yeah, duh), after you insert a value to them Example:

var1 = 1
var2 = 10

String Data:

Astring, in Python, is defined as a set of character between quotation marks, and the subsets using “[ ] ” and “[ : ]”. Example:

#!/usr/bin/python

str = 'Hello World!'

print str          # Prints complete string
print str[0]       # Prints first character of the string
print str[2:5]     # Prints characters starting from 3rd to 5th
print str[2:]      # Prints string starting from 3rd character
print str * 2      # Prints string two times
print str + "TEST" # Prints concatenated string

Resulting in the next answer:

Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST

List data

To write a list you must assign values, using “[]” and “[:]” , and the command “list”. These values order are listed starting at 0, basically making the 0 like a 1 if we refer to the normal way to count numbers (you know, the way they taught you in elementary). Example:

#!/usr/bin/python

list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']

print list          # Prints complete list
print list[0]       # Prints first element of the list
print list[1:3]     # Prints elements starting from 2nd till 3rd 
print list[2:]      # Prints elements starting from 3rd element
print tinylist * 2  # Prints list two times
print list + tinylist # Prints concatenated lists

Creating the next result:

['abcd', 786, 2.23, 'john', 70.200000000000003]
abcd
[786, 2.23]
[2.23, 'john', 70.200000000000003]
[123, 'john', 123, 'john']
['abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john']

More examples at:http://www.tutorialspoint.com/python/python_variable_types.htm


Zen of Python

--Originally published at Programming Fundaments

The Zen of python is an entry in the Python Enhancement Proposals (PEP), these are a collection of softeare principals that influences the desings of Python. 19 are written by Tim Peters, an Python pilgrim, these were written among june 1999.

This text is free domain at: https://github.com/python/peps/blob/master/pep-0020.txt

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!



Use of Comments

--Originally published at Programming Fundaments

Comments are, as the name implies, annotacion that you can add up to your work, as such these will not affect your strings in any way , these are just add on that you can use at any given time.

iilusSimply by using “#” python will ignore the text after the sign until the end of the line, python does not take as part of the code.

 


How to install Python (From Cygwin)

--Originally published at Programming Fundaments

This way of instaling Python its more efficient that the normal way, so problably you would want to check out this way before you start programming.

First, install Cygwin with these next packages

python
python-paramiko 
python-crypto  
gcc  
wget 
openssh 

Then, with Cygwin alrady installed, type python in Cygwin

After that install all the toolsetups at: https://pypi.python.org/pypi/setuptools

Inside Cygwin use easy_install to install request and pustil.

And from there on you can use python inside Cywing, and thats one way to start programing

For more information check at: https://github.com/h2oai/h2o-2/wiki/Installing-Python-inside-Cygwin