Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Closed Thread
 
Thread Tools Display Modes
Old Dec 7th, 2008, 10:52 PM   #1
Xarver
Programmer
 
Xarver's Avatar
 
Join Date: Oct 2008
Posts: 42
Rep Power: 0 Xarver is on a distinguished road
Send a message via MSN to Xarver
Lightbulb Basics of Python

"Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code." ~ Python.org

It can be called a "scripting language" but is very powerful and has extreme capabilities.
We will be using Python 2.6 for this tutorial.

Onto the basics:

The Official Python Website
Download the latest version and install on your computer.
Some operating systems may already have it.
I will expect you have some kind of editor of some sort.
Here's a list of them.


We're going to make a program that asks for a name.
Type this into your editor and save it as hello.py
(.py is a python command line program, .pyw is a non-console application.)
python Syntax (Toggle Plain Text)
  1. #!/usr/bin/env python
  2. name = raw_input('Enter your name: ')
  3. print 'Hello', name
  4. raw_input
Run the program and you should get the following output:
Quote:
Enter your name: example
Hello example
When you press enter it should close.

Explained:
I'll explain this line by line.
The first line is for Unix/Linux users.
The first line of the program that has that will search usr/bin for python.
Then it will run your program with it.

The second line assigns a variable with the = operator
name is our variable, and it is assigned to raw_input
raw_input is input for strings.
In the () we ask for the person's name. You could even put
name = raw_input('Monkey breath. ')
If you wanted to.
Also, variable names are case sensitive so name and NaMe aren't the same.

The third line prints Hello then prints the variable name.
name is the entry the user entered.
So If I put Xarver it would say Hello Xarver
The comma after Hello is something used to add another thing and adding a space.
So, print 'hello ', 'world' would print hello world.

The last line is raw_input which gets string input.
It's not assigned to a variable so It just waits for entry then continues on.
And there's nothing else to do, so the program ends.

That's the end of the tutorial.
if interested in Python here's a great tutorial: Byte of Python

I hope you learned something!

~ Xarver
Xarver is offline  
Old May 13th, 2009, 12:50 PM   #2
cody.soyland
Newbie
 
Join Date: May 2009
Posts: 2
Rep Power: 0 cody.soyland is on a distinguished road
Re: Basics of Python

A very good beginner's resource is Dive Into Python, a free book: http://www.diveintopython.org/toc/index.html
cody.soyland is offline  
Old Dec 24th, 2009, 8:53 PM   #3
cid49
Newbie
 
Join Date: Nov 2009
Location: philippines
Posts: 2
Rep Power: 0 cid49 is on a distinguished road
Re: Basics of Python

@xarver

hello i feel that your thread is very useful to beginners like me. hope you can recommend an editor or you can share an editor for me so that i can follow your tutorial. actually i am zero in knowledge when it comes to programming but i want to learn the subject no matter what. hope you continue to post here and consider me as your student....merry christmas . tia
cid49 is offline  
Old Dec 29th, 2010, 2:57 AM   #4
benschrist
Newbie
 
Join Date: Dec 2010
Posts: 5
Rep Power: 0 benschrist is on a distinguished road
Re: Basics of Python

I've found it quite useful in improving my python skills, and it gives your brain a good workout at the same time.Python programs can be written using any text editor and should have the extension .py.It is a very high level language.Instead of braces,blocks are identified by having the same indentation.
__________________
acekard
benschrist is offline  
Old Aug 24th, 2011, 7:52 PM   #5
bella10388
Newbie
 
Join Date: Aug 2011
Posts: 1
Rep Power: 0 bella10388 is on a distinguished road
Re: Basics of Python

Quote:
Originally Posted by cody.soyland View Post
A very good beginner's resource is Dive Into Python, a free book: http://www.diveintopython.org/toc/index.html

Such a very amazing link!
__________________
Watch Zookeeper Online Free
bella10388 is offline  
Old Aug 24th, 2011, 8:20 PM   #6
titaniumdecoy
Programming Guru

 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Location: California
Posts: 1,535
Rep Power: 14 titaniumdecoy will become famous soon enoughtitaniumdecoy will become famous soon enough
Send a message via AIM to titaniumdecoy
Re: Basics of Python

Closed old thread.
titaniumdecoy is offline  
Closed Thread

Bookmarks

Tags
python tutorial

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perfect Python Dietrich Python 30 Jan 5th, 2007 12:38 PM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Convert Python script to C++ code clanotheduck Python 17 Sep 25th, 2005 8:55 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 7:39 AM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC