Just starting out with Python

10 views
Skip to first unread message

Mark

unread,
Dec 1, 2011, 5:42:33 AM12/1/11
to cam...@googlegroups.com
Hi there,

I'm just starting to learn Python, and was wondering if anyone could suggest some resources? So far, I've been able to look into the basic syntax and have (something of) a grasp on it, but any advice in getting started would be much appreciated. 

In addition to any resources, I was wondering if anyone could help me out with For Loops. I understand how to make them work, and the basic syntax behind them: 

However, I'm struggling to understand exactly what happens, or what these loops are for. 

In the below, when I print a, it prints the numbers 1 through 5 (from myList). However, what do I do if I don't want to print a just yet? If I want to assign a to myList, but then print it later? And what is the benefit of printing it anyway? Any advice would be fantastic.

  1. myList = [12345]  
  2.   
  3. for a in myList:  
  4.     print a  

Thanks a lot :)

David Guaraglia

unread,
Dec 2, 2011, 1:33:05 PM12/2/11
to cam...@googlegroups.com
Hi Mark!

One of the best things about Python is that there are plenty of free
resources out there. To start with, I'd suggest one of the many free
books on Python. The ones I know and can recommend to a certain extent
(I've only read them cursorily):

- Learn Python the Hard Way: http://learnpythonthehardway.org/
- Dive Into Python: http://www.diveintopython.net/
- A Byte of Python: http://www.swaroopch.com/notes/Python

I heartily suggest you go through one of those books as you seem to be
somewhat new to programming and they were designed *exactly* with that
case in mind.

One thing to consider about Python is that a big part of learning it
is learning about the ecosystem, rather than just the syntax. Once you
are fluent in the idioms and general control structures you should get
acquainted with the myriad of freely available excellent libraries
that do all kinds of stuff for you. A simple Google search for "how to
do X in Python" will normally point you in the right general
direction, sometimes providing a snippet that'll do 99% of what you
do. I know that simple procedure has saved me hundreds of hours of
reinventing the wheel :)

As for your question... well, it's rather a trivial or deep one,
depending where you come from. From it I understand you don't quite
grasp the idea of variables yet, am I right? 'Printing' is the
simplest operation you can perform on a variable, and is normally used
in books as a placeholder for more interesting things to come. In
other words: if you can "print" a piece of data, you'll be able to do
pretty much whatever to it later on, and that's where the fun starts!

Anyway, I wish you the best of lucks with your new Pythonic endeavour.
Don't get discouraged if at some point you seem to get stuck in an
example or concept. Just keep at it, drop a question around here and
it'll 'click' at some point. I learned programming from reading books
way before doing uni, and it was a painful but extremely rewarding
experience!

Regards,
David

> --
> You received this message because you are subscribed to the Google Groups
> "Cambridge and East Anglian Python Users Group" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/campug/-/o6_y32AW3rcJ.
> To post to this group, send email to cam...@googlegroups.com.
> To unsubscribe from this group, send email to
> campug+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/campug?hl=en.

louis taylor

unread,
Dec 1, 2011, 6:40:43 PM12/1/11
to cam...@googlegroups.com
On 1 December 2011 10:42, Mark <mark...@gmail.com> wrote:
> Hi there,

Hello!

> I'm just starting to learn Python, and was wondering if anyone could suggest
> some resources? So far, I've been able to look into the basic syntax and
> have (something of) a grasp on it, but any advice in getting started would
> be much appreciated.

A great place to get started is `Think Python`
(http://greenteapress.com/thinkpython/thinkpython.pdf) and `A Byte of
Python` (http://www.ibiblio.org/swaroopch/byteofpython/files/120/byteofpython_120.pdf).

> In addition to any resources, I was wondering if anyone could help me out
> with For Loops. I understand how to make them work, and the basic syntax
> behind them:
>
> However, I'm struggling to understand exactly what happens, or what these
> loops are for.

For loops just iterate over a set of commands a predefined number of
times with a variable to keep track of the looping. Take a look at
http://en.wikipedia.org/wiki/For_loop for a better description.

> In the below, when I print a, it prints the numbers 1 through 5 (from
> myList). However, what do I do if I don't want to print a just yet? If I
> want to assign a to myList, but then print it later? And what is the benefit
> of printing it anyway? Any advice would be fantastic.
>
> myList = [1, 2, 3, 4, 5]
>
> for a in myList:
>     print a

I'm not sure what you mean here. You can do:
firstList = [1, 2, 3, 4, 5]
secondList = []
for a in firstList:
secondList = secondList + [a + 10] #adding 10 to each number
to make it a bit more interesting

Printing has no effect if you don't want to see the contents of the
list when you run the program.

>
> Thanks a lot :)
>

No problem :-)

--
--Louis Taylor--
http://louistaylor.wordpress.com/

Reply all
Reply to author
Forward
0 new messages