Jump to content
xisto Community
Ahsaniqbalkmc

Learnin Python -- Where To Start?

Recommended Posts

You will probably have to take care with pointers.You are using a pointer in your first exemple of errors, no real problem but keep in mind that the things whose name start with "&" are pointers, not numbers.

Share this post


Link to post
Share on other sites

Well, I didn't knew that things whose name start with & are pointers. The book I am using stated something like: It is not the right time to explain why & sign is used before the name of the variable but it will be explained latter. Something like this (If I remember it correctly).So what more you have to say about pointers..

Share this post


Link to post
Share on other sites

Let's see later how your book explains this. Pointers are direct access to parts of the system memory, for instance the place where the value of this variable is currently stored in system memory.

Share this post


Link to post
Share on other sites

"hate" is such a harsh word.

How much time do you really have, and how long are you going to put the effort into learning it? Most people wanting to learn programming, just want to get it done quickly, bypass the essential learning and just focus on what they want to create, so it can be easy to find a lot of poorly written code out there.

I know both C/C++ and Python, but they aren't the only languages I know but they can have some solid learning grounds for any programming. C/C++ seem to have the consistent language idioms that other languages follow, while Python has an easier thinking process that simplifies some of the complexities that C/C++ has but can also introduce other complexities.

If programming as a career, I would lean towards C/C++, if as a hobby I would go towards Python. I'm not saying Python is a hobbyist language though, it is very powerful and my preferred language at the moment due to how easily I can whip something up. My pro for python dynamic type, quick development time and multiplatform support, my pro for C/C++ is usually faster running programs, longer history and that it is very powerful. The best of both worlds, code in Python can be rewritten in C/C++ to speed up those areas that may cause bottlenecks.

I just thought of another reason to go with Python... no pointers. That's actually a good reason too, because explaining pointers is quite hard as it has numerous amounts of usage that changes it's definition where saying a pointer could be this, it can also be such and such.

"&" in front of a variable name, when used this way and not with two operands like the bitwise 'and' operator is actually the address-of or reference operator. This does not always mean you're working with pointers. It is used to get the address of items in memory in which a pointer can point to.

#include <iostream>using namespace std;int main(){int cats = 7;cout << "There is " << cats << " cats at this memory address " << &cats << endl;return 0;}

This could result in something like:

#$ There is 7 cats at this memory address 0xeffffc0c

Things I can say about pointers, they must have a type. A pointer that points to integers is an integer pointer. To declare an integer pointer and not a simple int we use an asterisk '*', like this:

int *pointer;

To use an integer pointer, we first need to store data in an integer variable and then store the address of the integer variable in the pointer and we may as well access the data it points to by dereferencing it:

#include <iostream>using namespace std;int main(){int integer;int *pointer;integer = 5;pointer = &integer;cout << "The value of the integer is: " << *pointer;return 0;}

Which should result in:

#$ The value of the integer is: 5

This a just a simple usage of pointers, you can also get pointers to functions, objects and a whole lot more. Reasons to use pointers, well, it's all to do with memory management which Python handles for you.

So, if I was going to go for an easy language to learn... it would be Python.

Just to show why, to get similar to what was written above in Python

#!/usr/bin/env python#-*- coding: utf-8 -*-def main():    cats = 7    print 'There is', cats, 'cats at memory address', hex(id(cats))if __name__ == '__main__':    main()

Now I'm uncertain if hex(id(cats)) is the actual memory address or whether it should just be id(cats), we don't usually work with memory addresses.

Wow, I didn't want to remove what I wrote, even though it should be about Learning Python and where to start.

Python tutorial helps, then build on what specifically you want to do.

Cheers,


MC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.