Starting up with Python – Part1

I recently posted an article – Getting started with python and Anjuta. On this article, I will shed my experience, reviews, and additional research from TheNewBoston tutorial on Python to get myself refreshed up with Python techniques.

 

1.Numbers and Math

That looks pretty straightforward. The decimal point is very important here. You need to ask Python to perform Maths calculation in decimal points to get decimal point (floats) values. The modulus calculation is also interesting for example 9.4 % 2.32 which gives you the remainder in float 0.120000000000001 Exponent calculations are carried out as 3**10 to calculate 3 to the power of 10 which gives you 59049. Indeed, that is pretty cool.

2. Variables

As explained, Variable acts as a storage for a temporary value. For example:

 

>> x = 2
 >>> x ** 10
 1024

We can also use assigned a variable with the input function input() For example:

 

>> a = input("Here is a number: ")
 Here is a number: 10
 >>> a**2
 100

As per the Wikibooks of Python Programming, there are two types of input function that is, input() and raw_input(). raw_input() asks the user for a string of data (ended with a newline), and simply returns the string. It can also take an argument, which is displayed as a prompt before the user enters the data. input() uses raw_input to read a string of data, and then attempts to evaluate it as if it were a Python program, and then returns the value that results.

One of the difference is that in Python 3.x raw_input() was renamed as input()

Next article on Modules and functions

Nitin J Mutkawoa https://tunnelix.com

Blogger at tunnelix.com | Founding member of cyberstorm.mu | An Aficionado Journey in Opensource & Linux – And now It's a NASDAQ touch!

You May Also Like

More From Author