pyhton...

Pages: 12
i need some sample programs of python..
just simple program!!
ex: ask user to input any variables...

i dont have any background of this language...
pls help me!thanks!! ;)
Why would you want us to do this for you when it seems you are looking to do no work yourself? And why are you posting this in a C++ forum?
amf!! im sorry.. im just asking, i thought python have some similarity of c++ so i just people here in this forum... so if you dont like to help me.. fine!! thanks anyway......
Question wrote:
What's the difference between Python and C++
Answer wrote:
It'd be much faster to state what they have in common


Taken from a python tutorial for C++ developers. basically the only thing they is the possibility of object oriented code. and that's only achieved in python through metaprogramming.
ahh,,, thanks Seraphimsan ;>
and that's only achieved in python through metaprogramming.

How so? Why is this metaprogramming:

1
2
3
4
5
6
class Foo(object):
    def __init__(self):
        self.bar = 1

    def some_method(self, n):
        return n * self.bar
?

And how is it different from:

1
2
3
4
5
6
7
8
9
class Foo {
public:
    Foo()
    :bar(1) { }

    int some_method(int n) { return n * bar; }

    int bar;
};
?
What? The only thing they have in common is the possibility of object oriented code??? And that's only achieved in Python through metaprogramming???

No and no.

What do they have in common? Both are general purpose languages that support elements of procedural, object-oriented and functional programming paradigms, easily mixing all three styles. Both have an ALGOL-based syntax.

Python is notable for enforcing block structure with whitespace (indentation).

C++ is notable for its backwards compatibility with the C language.

The two most noticeable differences are A) Python (CPython specifically) is an interpreted language whereas C++ is (typically) compiled, and B) Python is a dynamically-typed language while C++ is statically typed.

Various tools makes it easy extend Python with modules written in C++. And the CPython interpreter can be embedded in C++ applications.

The best place for Python examples is here: http://docs.python.org/tutorial/
The best place to ask for help is here: http://groups.google.com/group/comp.lang.python/topics

I'm sure others can add considerably to this, but these are the key points for me.

Edit: And what filipe said.
Last edited on
well crap, I was thinking of lua XD sorry guys, my bad
edit: take that back, I don't have a clue where i got that ._.;; I shouldn't talk to people :P
Last edited on
1
2
3
4
5
print "hello world"
# or in python 3.0

print("hello world")


There's a "sample program" for ya!

btw python isn't hard so instead of asking us for programs just find a good guide...

http://www.sthurlow.com/python/lesson02/

sorry that the link is to lesson 2 but thats what I had bookmarked...
if you cannot be bothered to research yourself, why are you
studying?

maybe consider another career in sales or advertising?
+1 bigearsbilly
This stuff is all over the web if you just search "Python example code"...

http://code.activestate.com/recipes/langs/python/?query_start=1
http://tinyurl.com/4gsywvx - this should help
Object Oriented is a style of programming, not a language feature. Just because you say animal.nomnomnom(cracker); instead of nomnomnom(&animal,cracker); doesn't mean that one is OO and the other is not. They are both OO.
Last edited on
bigearsbilly wrote:
if you cannot be bothered to research yourself, why are you
studying?

maybe consider another career in sales or advertising?


Sales and advertising also demand extensive researching. =(
rocketboy, actually, it's a programming style AND an language feature. In languages that do not support object orientation object oriented programming can usually only be done very superficially.
What do you mean by "superficially"? OO is enabled by the more generic feature of 'record types', that is data structures with non-homogenous types. And what particular feature would you say constitutes support for object orientation? Inheritance? The object.method syntax sugar? Perhaps operator overloading or templates? Or encapsulation? (which is easily obtainable in C; look at HWND or FILE*).
Last edited on
OOP is by definition encapsulation, and I already admitted that I was mistaken, stop this argument. It's childish.
First of all, it would have to support objects. Which means entities with encapsulated data and methods to operate on that data.

For programming object oriented, it would also have to support inheritence and polymorphy, templates are not necessary (actually, templates have nothing to do with object orientation at all- at least not the C++ templates).

With HWND: it's just a number. I don't really get what you're getting at here. Neither FILE structs nor HANDLE's have anything to do with object oriented programming, so I don't really know what you're getting at here.

And you can emulate object orientation in procedural languages, but you can not program object oriented.
FILE structs are encapsulated. They are forward-declared, so even if you knew the members, you would not be able to access them. Furthermore it's actually better encapsulation than in C++, because a change to the members of FILE would not trigger recompilation of the code using it.
Inheritance and polymorphism are also used in supposedly non-OO languages. For example, the Event union in SDL uses polymorphism to support a variety of events to by stored in the same variable.
These examples show that OO is not a language feature. Many language features help achieve it, but the concepts are universally applicable.
EDIT: Also, methods are just syntax sugar for functions which take an object as an argument.
Last edited on
Pages: 12