Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.

Share tech news, updates, or what's on your mind.

Sign up to Post

For loop in Python
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
0
Free Tool: Site Down Detector
LVL 9
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

The purpose of this article is to demonstrate how we can use conditional statements using Python.
0
Introduction of Lists in Python:
There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can also say like the place holder where a number of elements can be stored in a given order. 

We can use lists for indexing , adding , multiplying or checking for the member of that sequence. We can also check the lenght by identifying the minimum and maximum elements present in the lists. 

Lists are called as the compound data types of Python. The lists are separated by commas and enclosed by square brackets i.e. [].
Lists are very similar to arrays in C programming language but the difference is that Python lists can be of different data types.
 
Slice operators are used to access the values from a list for example ( [] ] OR [] : ] ) . The indexes starts with zero i.e. "0" from beginning and if we starts the index from
the end then it starts with negative one i.e. "-1" . We can use a plus sign (+) for concatenate a list and an asterisk sign (*) to repeat the list.
 
Let's try to see how a simple list can look like :

 
login as: sloba
sloba@*********'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic x86_64)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
Last login: Mon Jul 13 14:18:53 2015 from 172.27.66.246
sloba@sloba-VirtualBox ~ $ python
Python 2.7.10 

Open in new window

2
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once you download and install Linux Mint 17.2, Python software is installed by default. But the latest releases from Python are Python 2.7.10 and Python 3.4.3. I am using a 32 bit operating system as my host is 32 bit but you can still go ahead with 64 bit version which is preferred.

Log into the Mint operating system, and open terminal. Type "python" and hit enter or you can type "python --version" to check the existing version.
swadhin.ray-000036.pngTo download the latest version of Python, open https://www.python.org/downloads/ and click on "Download Python-2.7.10" as shown in below image.
swadhin.ray-000037.pngOpen the folder where the file is downloaded. In my system it's defaulted to "Downloads" folder.
swadhin.ray-000038.png
swadhin.ray-000039.pngIf you open the tar file from the archive manager you can see the files that were downloaded.
swadhin.ray-000040.pngNow extract all the files under the same folder or you can choose a specific directory. Click on Extract button as shown below.
swadhin.ray-000041.pngswadhin.ray-000042.pngWait till the file get extracted.
swadhin.ray-000043.pngNow from the above image we can we can see that file is successfully extracted.
swadhin.ray-000044.pngNow open terminal and locate the extracted installation files.

Open in new window

1
 

Expert Comment

by:MeganDS
Comment Utility
When I executed "./configure", you said it shouldn't have any errors, but mine did. When I did that, I got this output:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR... 
checking for --without-gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/sara/Downloads/Python-2.7.10':
configure: error: C compiler cannot create executables
See `config.log' for more details

Open in new window


What can I do to fix this?
0
 
LVL 16

Author Comment

by:Swadhin Ray
Comment Utility
what is your OS version seems you are installing 64/bit on 32 .
0
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can define dictionaries using dictionary construct.
First of all we need to define a dictionary:
Syntax:

<Name of the Dictionary >= {<key1> : <Value1> , <key2> : <Value2>,...., <key n> : <Value n> }

Open in new window


 
From the above syntax the value can be integer may not be enclosed by single/double quotes and separated by commas.
Example:
 
>>> COURSE ={'ORACLE': 1 ,'LINUX' : 2, 'SHELL' : 3 ,'PERL' : 4 }
>>> type(COURSE)
<type 'dict'>

Open in new window


The dictionaries are also case sensitive. We can access the above dictionary as like below:
 
>>> COURSE
{'ORACLE': 1, 'PERL': 4, 'SHELL': 3, 'LINUX': 2}

Open in new window

This will display the key and values within the dictionary, this are not ordered and if we want the dictionary to be in order then we have to sort it by values as the each key can be unique.
If we want to display the value specifically then we can call the dictionary by each key as like below:
 
>>> COURSE ['PERL']
4

Open in new window


Now if we want to add another element let say ‘PYTHON’ as value 4 then use as below:
 
>>> COURSE ['PYTHON']  = 4
>>> COURSE
{'ORACLE': 1, 'PERL': 4, 'PYTHON': 4, 'SHELL': 3, 'LINUX': 2}
>>> 

Open in new window

 
Now if I want to change the value of the key Linux then we have to use as like below:
>>> COURSE ['PYTHON']  = 9
>>> COURSE
{'ORACLE': 1, 'PERL': 4, 'PYTHON': 9, 'SHELL': 3, 'LINUX': 2}
>>> 

Open in new window

If we want to display the keys and values of a dictionary then we have to execute the name of the dictionary with key or values as like below:
 
>>> COURSE.keys()
['ORACLE', 'PERL', 'PYTHON', 'SHELL', 'LINUX']
>>> COURSE.values()
[1, 4, 9, 3, 2]

Open in new window


For deleting the key value pair from the dictionary created then we have to use :
 
>>> del COURSE['PERL']
>>> COURSE
{'ORACLE': 1, 'PYTHON': 9, 'SHELL': 3, 'LINUX': 2}
>>> 
 

Open in new window

Now we can see that the element PERL is deleted from the dictionary.
Let us see how we can loop the dictionary values:
 

Open in new window

1
 
LVL 46

Expert Comment

by:aikimark
Comment Utility
@pepr

There's a lot of version 2 Python development still being done.  Some packages, such as Portable Python, are version 2.
0
 
LVL 29

Expert Comment

by:pepr
Comment Utility
@aikimark: This was my opinion. Beginners should start with the state-of-the-art version of the language, in my opinion. Some operations used in the article are Python 2 specific, and they would look differently in Python 3.

There is also a lot of Fortran and Cobol code around.
0
Sequence is something that used to store data in it in very simple words. Let us just create a list first.
To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed by square braces as like below:
 
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> COURSE = []

Open in new window


 
Now we have to add all the elements within the square brackets. So now let us add the elements within it.
 
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> COURSE = ['PYTHON', 'PERL','ORACLE','MYSQL','BASH']

Open in new window


 
After keeping the entire element that we want to be added within the list hit “enter”.
Now we have stored our list of elements with in a variable i.e. COURSE but internally python will assign numbers to each element of the list which are been stored starting with zero.
It assigns as like below order:
 
  • PYTHON  as 0 “zero”
  • PERL  as 1 “one”
  • ORACLE as 2 “two”
  • MYSQL as 3 “three”
  • BASH as 4 “four”
Even there are five elements are present but still it will start with zero and ends with four.
Sequence plays an important role because we can access member or element of the list by indexing.
 
So if we now want to access only Oracle from my list i.e. “COURSE” then I can simply call it by using indexing as like below:
 
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> COURSE = ['PYTHON', 'PERL','ORACLE','MYSQL','BASH']
>>> COURSE[2]
'ORACLE'

Open in new window


 
But the list COURSE is case sensitive.  For example if I want to access as below then I get list is undefined.
>>> course[2]

Open in new window


 
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    course[2]
NameError: name 'course' is not defined

Open in new window


 
Now in python they made the indexing in reverse way too which starts with negative (–ve) from end to beginning.  So in reverse way if we want to access then it will be like as below:
  • PYTHON  as -5 “negative five”
1
 
LVL 46

Expert Comment

by:aikimark
Comment Utility
You need to differentiate a sequence from a list.

Although you can address list items numerically, I do not think that there are internal number assignments made.  It is a wrong interpretation of "associated".
0
 
LVL 16

Author Comment

by:Swadhin Ray
Comment Utility
>> List : A built-in Python sequence.
Reference : https://docs.python.org/3/glossary.html#term-list

But yes there is a difference. Sequence are to get the items from the order list.
0
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7.

Lets install Flask!
To install Flask you can use a python repository for libraries tool called pip. Download this file Python Pip and save it as 'get-pip.py'
To run it:
Windows -
python.exe get-pip.py
Linux -
python get-pip.py
Actually using pip to install flask:
pip install flask
Great, now Flask is installed as a python library and can be used in any python script.

In the beginning we'll just be able to connect to our web application through http://localhost:5000/ and later we will can make it available to anyone on the internet!

To start our project, create a folder that will house your files. We'll be using a special folder structure that flask will use to find correct .html, .css, image files and .js files.

Name your folder whatever you want and put it somewhere easily accessible. I called mine "MyWebApp". Inside your folder create another two folders. One named "static" and another named "templates".
Excuse my horrid picture but it will do:
File StructureNow that you have created a organized directory, create a Python file named "main.py"

In this file you're going to want to add this Python code.
 
#!/usr/bin/python2
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Open in new window


Let's break down the code.
#!/usr/bin/python2
This can be ignored for windows users. If you're using linux this tells the compiler when you run the file as an executable to compile it with python2

from flask import Flask
4
 
LVL 15

Administrative Comment

by:ericpete
Comment Utility
Pasha,

Congratulations! Your article has been published.

ericpete
Page Editor
0
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modifies it, and then returns the results.

In Python we can create the strings by using single quotes, double quotes and even using triple quotes. For example:
Using single quotes:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 'This is my first srting'
'This is my first srting'
>>>

Open in new window

Using double quotes:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> "This is my double quote string"
'This is my double quote string'
>>> 

Open in new window

Using triple quotes:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> '''This is my tripe quote string'''
'This is my tripe quote string'
>>> 

Open in new window

It really doesn’t matter what type of string we use unless we are looking to derive from the result. For example we are using something like “It’s a nice place ”, then in this case, because we have a single quote in our original string we cannot use single quotes before and after the sting.

Example:  
>>> 'It's a nice place'
SyntaxError: invalid syntax
>>> 

Open in new window

So to use this type of string we need to use double quotes such as below:
>>> "It's a nice place"
"It's a nice place"
>>> 

Open in new window

We can also use the backslash ‘\’ to run the same string with single quotes.
Example:
  
>>> 'It\'s a nice place'
"It's a nice place"
>>>

Open in new window

Similarly the example below will show how to use the backslash when we are using double quotes within a double quote string:
>>> " Sam asked "Did you get my key ?" to Hari "
SyntaxError: invalid syntax
>>>

Open in new window

To run this string we can use the backslash or triple quotes as shown below:
>>> " Sam asked \"Did you get my key ?\" to Hari "
' Sam asked "Did you get my key ?" to Hari '

Open in new window

>>> ''' "Sam asked "Did you get my key ?" to Hari'''
' "Sam asked "Did you get my key ?" to Hari'
>>>

Open in new window

So, how do we use a string inside a variable? Lets pass a string inside variables:
>>> x="Steve"
>>> y="jobs"
>>> x+y
'Stevejobs'

Open in new window

Just to make a little difference on the above example, let’s put a space in between the Steve and Jobs.
>>> x+'   '+y
'Steve jobs'

Open in new window

0
 
LVL 15

Administrative Comment

by:ericpete
Comment Utility
slobaray,

Congratulations! Your article has now been published.

ericpete
Page Editor
0
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it.

Module is an object with arbitrarily named attributes which can be used in binding and referencing.

We can define a function, classes and variables inside a module; it can also have the runnable code.

Example: There is a function called "FLOOR" which is used to round the value for the given input to it. This function is inside a module that allows us to use it.

Let us check if we are able to use this function or not:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> floor(17.5)

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    floor(17.5)
NameError: name 'floor' is not defined
>>>  

Open in new window

Here from the above we can see that the error as this function is not present on my Python because we have not imported the Module which is holding this function.

Let us import the module i.e. "MATH" which has "FLOOR" function.

>>> import math

Open in new window

Now let us use the "FLOOR" function again and check if we are able to use it:
>>> floor(17.5)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    floor(17.5)
NameError: name 'floor' is not defined

Open in new window

But still we see the same error because we cannot use the function like the above statement, in order to use we must provide the module name at the beginning and then the function name to it as like below:

>>> math.floor(17.5)
17.0
>>> 

Open in new window

So now we are able to use the "FLOOR" function.

To check what are the other modules present in the math module we can hit ">>> math." and hold for a sec it will display all the functions associated with it. Or by using "dir()" which is a built-in function which will return the list of the names defined inside a module as like below:


Open in new window

0

Introduction

On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced with the version. This article was written for those of you who work with more than one version of Python on one computer, and who have not noticed the Python Launcher yet.
 

Summary

If you set the environment correctly, the Python launcher allows you to launch both your Python 2 and Python 3 scripts the same way:

py older2.py
py newer3.py

Open in new window

Working from cmd window, you can also left out the py and launch it as if the script were executable:

older2.py
newer3.py

Open in new window

You can even omit the extension when launching from the cmd console:

older2
newer3

Open in new window

or--if you prefer--it allows you to launch the Python application using mouse double-click on the script icon. The version of Python that is to be used for interpreting the script can now be captured inside the script. And this is a good thing.
 

Unlucky scenario in Windows (compare to Unix-like systems)

First, a bit of Unix evangelism for those who went astray...

When MS Windows is finished, it will be the best documented Unix in the World.
                              (A prophet unknown to me -- some say that Joker is her name.)
Unix uses very clear, simple, and clever abstractions from the very beginning. A file
4
 
LVL 15

Expert Comment

by:ericpete
Comment Utility
Congratulations; your article has been published.

ericpete
Page Editor
0
Want Experts Exchange at your fingertips?
LVL 9
Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we save it.

So when we use Python IDLE(GUI) we can navigate to "File" and then click on "New Window" or we can use shortcut i.e."Ctrl+N" which will open a new text editor where we can write our program and save it into any location on the operating system. From the new window we can execute our program too.

Below are the screen shots taken after opening IDEL and then opening a New window.
Opening a new window
New window

Now let us write a simple program and save it on any location, but when we save the file the extension of the file name will always be ".py" :

x = raw_input("Enter your name : ")
print "Hello  " + x

Open in new window


Once it is saved on your system then navigate to "Run" and click on "Run Module" or "F5" which will run on the Python Shell as like below:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Enter your name : Sloba
Hello  Sloba
>>> 

Open in new window


I have named this program as "test.py". Below is the image of the file that I have saved it on my desktop.

Now we can also run this program by simply double click on it. But we will be unable to see the result after we enter the name as I have shown earlier, because it is processed so fast that we cannot see if the printed the input successfully or not.
So for avoiding this let us modify the program a bit and execute it from my desktop.

Modified code:

Open in new window

0
 
LVL 16

Author Comment

by:Swadhin Ray
Comment Utility
Thanks a lot  to catching this out :-)...  will change it right now ..

Regards,
Sloba
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
Comment Utility
Since there is more than one IDE option for python, should the title of the article not be:  "Saving Python Programs in IDLE", or similar?
0
This article will show the steps for installing Python on Ubuntu Operating System.

I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS.

For installing Python we need to download Python on our operating system and then install it.
Creating and installing Ubuntu on Oracle VirtualBox can be seen from my blog i.e. : http://slobaexpert.wordpress.com/2012/06/10/installing-ubuntu-on-oracle-vm/

Below are the details steps for installation assuming that we have installed Ubuntu OS :

Step 1) Open Ubuntu from Oracle VirtualBox (Note: we can also use VMware instead of Oracle VirtualBox):

image 1
Step 2) Navigate to 'Application' then click on  'Accessories' and finally open a new 'Terminal':
image 2
image 3
Step 3) Type 'sudo su' and keep it aside, so in the mean while we can download Python:

image 4
Step 4) Open Mozilla Firefox and go to Python official web site i.e. http://python.org/:

image 5
image 6
Step 5) Navigate to Download tab and download Python :
image 7
Download the latest version:
image 8
Once clicked on the link we will be asked to either open it or save it as like below:
image 9
Click 'OK' :
image 10
image 11
image 12
image 13
Step 6) Go to your desktop and extract the file there(you can also choose your own folder or path where you want to extract but here I am extracting it on the desktop ):
image 14
image 15
image 16
image 17
0
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the data type of a variable for what we can store in the reserved space.
Let us see now how we can create a variable in Python. First we need to create a variable name and then we can assign it to a value.

Example of a simple variable:
Let us create a variable name called “X” and assign a values to it for example take 20. As like below:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> x= 20
>>> 

Open in new window


Note: Type “x=20” and hit enter.

So now we can use variable ‘x’ i.e. 20 can be used where ever we want to use it , where ‘x’ represent the value 18.
If we want to do a sum like 20+ 50 which should result me 70 but in place of 20 I can the assigned variable i.e. ‘x’.
Below example shows how to do that:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> x= 20
>>> print x+50
70
>>> 

Open in new window


Now for example we want to do an exponent 3 then the result will be like:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> x= 20
>>> print x+50
70
>>> print x ** 3
8000
>>> 

Open in new window

From the above example we can see how to assign single variable for a value which we can use it later in our code.
Now let see how we can use multiple variables for different values.  So from above we know that x which represents value 20 and now we will take another variable called ‘y’ where we will assign value 10 to it and do a sum for x+y then the result will be 30 i.e. 10+20= 30..

Open in new window

0
 
LVL 16

Author Comment

by:Swadhin Ray
Comment Utility
We can also say as variable is something like a bucket where we can put anything that we want.
But space I still agree.
0
 
LVL 29

Expert Comment

by:pepr
Comment Utility
Well, but if the object takes say 1 kB, it is created before any Python variable for that object is created. Variable in Python means something else than variable say in C++. A variable in Python is unrelated to the memory footprint of the object. When the unnamed object exists, the variable is simply the name bound externally to the object. The name is not translated to the address of memory space of the object. The name is not directly related to the placeholder of the object.

Assigning the above mentioned object with say 1 kB foot print means that say few bytes more are allocated -- much less than the object size. The object is not copied. It is only shared via the variable. The variable can immediately be assigned another object. If the other object already existed, no extra memory is allocated in the case.
0
Installing Python 2.7.3 version on Windows operating system

For installing Python first we need to download Python's latest version from URL" www.python.org "
You can also get information on Python scripting language from the above mentioned web site.

Let's go and start installing Python on Windows Operating System.
The below steps will show how to download and install Python and test by printing message on it.

1) Go to www.python.org 

image1
2) Click on Download tab from the left side of the web page:
image2
3) There will be two production version Python 2.7.3 and Python 3.2.3.

Choose as per your requirement.
I am going to choose Python 2.7.3 (Windows installer). As my system is 32-bit Operating System.

Click on “Python 2.7.3 Windows installer”.

Once clicked ,it will ask you to save to a particular location but in my case as I am using Google Crome browser so it will automatically download to path “C:\Documents and Settings\slobaray\My Documents\Downloads” as this is the default directory for Google Chrome browser to download files.

Go to the downloaded path and double click on the file i.e. downloaded “python-2.7.3.msi” for installing Python.

 image3
Click on “Run”

image4
4) Then we will be prompt by for choosing the setup for all users or only for the user i.e. installing Python product as shown below and I am choosing the default for all users:

image5
0

Less strange, but still introduction


This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some agreement.  Still, we always have to think in some context to understand the agreement.  You may say that what is described in this and previous articles is not related to Python basics at all.  It could be because you expect a text written in some context that you met when reading some other "basics".  The article series could be renamed to Python foundation or Python internals.  However, the later terms are more technical, and I do not think it would help you to understand what I want to write about.  Instead, I am asking you to change the context of thinking about it.  Tutorials often start with the simplest example that shows a working program (say "Hello, World!" -- it is also a kind of unspoken agreement bound to the "creation of a tutorial").  This is understandable.  There are many ways of how to attract a beginner's attention.  The context of "basics" in this series is based on "what you should know to understand".  I am focusing on "mental pictures of what is done" rather than on "how to write the block of code".  For that, I need also the text of this second part.  I am aware of the situation that you may want to skip these two articles with disagreement. ("Not related to Python…
2
 

Expert Comment

by:rgb192
Comment Utility
http://filedb.experts-exchange.com/incoming/2011/07_w29/478317/workingWithPointers.png
I do not understand the difference between
*
&

& is the address of var
* assign to the indirectly addressed memory

do I need * to change value of the pointer
0
 
LVL 29

Author Comment

by:pepr
Comment Utility
The & is the refrence operator (with the meaning "the address of"). The * is the dereference operator. If ptr points to a variable (that is if it contains the address of the variable), then using the *ptr you access the variable itself. You are not changing the value of the pointer. You are only using the address stored in the pointer variable to modify the variable that is pointed to.
0
"The time has come," the Walrus said,
"To talk of many things:
Of sets--and lists--and dictionaries--
Of variable kinks--
And why you see it changing not--
And why so strange are strings."
This part describes how variables and references (see parts 1 and 2) fit with Python, and how the clearly strange behaviour is not that strange when you know only a little bit more about the Python internals.  Some people may say: "Hey, they are not Python basics at all!"  The reality is that not having that little tiny bit of Python knowledge you will once stand schocked, with open mouth, staring at the behaviour of your program. Especially when you ARE a programmer (used to a compiled language).

If you find anything less understandable about variables and references in this article, have a look at Python illustrated (part 2).  Also, your feedback is warmly welcome.  It will form the problems illustrated in part 4.


 

Summary for Python variables/objects


You may not like to read a lot of "theory" first, and you may want to search where the conclusion is.  "Does it make sense for me to read further?"  Good news for you -- the summary from Python point of view comes first:

1. Everything in Python is an object. Any object has its unique technical identification (the memory address).  The information about …
3

The really strange introduction


Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Some years later, people chew pizza made of flour, enjoying their holiday in Italy, thinking of nothing -- definitely not about the grass seeds that were put to the soil. Still, the local bakers strive for perfection in baking The Best Pizza in The World, choosing carefully the kind of flour.

Another time, another places, there were individuals that played with first computers. They knew everything about their computer -- till the last bit. (Frankly, it was a bit easier as there was not so much bits inside as they are now.) Often, they built the computer. Or at least they fell in love with it and knew how to build it (also in cases when they bought it), and they replayed in their imagination "how they are rebuilding the same", feeling themselves strong, self-confident in the area. They knew "much more" about "much less" in comparison with our present time.

"Keep the ballance." The greatly admired people are often extreme people. They often brought us something very valuable, but they were not understood in their time, and they often died poor or in physical or in mental sense. In other words, being odd makes it sometimes easier to be great in something. The question is whether you want that. …
2
 
LVL 19

Expert Comment

by:jools
Comment Utility
This is probably one of the most surreal articles I've ever seen.

I need to learn python so clicking on Pyton basics seemed to be a good start (EE articles are generally pretty good). This article seems to miss the python part. I'll have a look at 2 and 3.

Nice job taking the time to write an article though!
0
 
LVL 29

Author Comment

by:pepr
Comment Utility
@jools Skim the part 3 first to decide.  They are probably not the articles to learn Python from zero.  They are rather articles for programmers of the classic languages who learn Python.  Sorry if misleaded by the title.  The content is rather meant "basics to understand why it works as observed".

Thanks for the reading and for the comment.
0
Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a primary programming language in an enterprise setup. In doing so, there are few parameters considered and the article revolves around the factors that would perhaps be critical in making the decision.

Code complexity / learning: Python might have an upper hand because of its sheer simplicity, therefore maintainability is quite good. The percentage of backend code is not more than 40% in general (in most of our applications). Therefore, it does not matter much as to what technology we choose for backend (‘non Flex’) code. Python or Java or C# –  result is same.

Links:
http://hathawaymix.org/Weblog/2004-06-16

Verdict:
Python is better in terms of simplicity and maintainability


Performance: Python is known to consume a lot of CPU in comparison with other technologies like Java or Microsoft (Article here explains more http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/). One interesting aspect is multi-threading – Python does support multithreading (but comes with certain limitations, that are perhaps the same with other languages as well: http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/).

Links:
3
 

Expert Comment

by:Articles101
Comment Utility
pepr,


Thanks for your help.


Articles101
0
 
LVL 29

Expert Comment

by:pepr
Comment Utility
I should clarify my last "Why?".   I mean "Why PRIMARY programming language?".  In my opinion, it leads to false belief that one language could solve all problems.  I believe that no programmer should pray for the God of a single programming language.
0

Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.