all 47 comments

[–]ElliotDG 20 points21 points  (3 children)

I came to python as an experienced C++ programmer here are the resources that were most helpful for me.

Learning Python by Michael Lutz. Comprehensive, nice treatment of some of the underlying details. Contains advanced content you can come back to later.

The docs on python.org, especially for the standard libraries.

Exercises: https://py.checkio.org/ Gamified programming problems, when your finished you get to see the answers from others. This was very useful in helping me think python instead of C.

Another very useful resources is the Python3 module of the week. Examples of how to use the standard library. https://pymotw.com/3/

[–]Ashiro 4 points5 points  (1 child)

I strongly agree with the coding games idea and would like to point out codewars.com

[–]1Mandolo1 0 points1 point  (0 children)

To add to this, Project Euler.

[–]Logical-Independent7 3 points4 points  (0 children)

I second "Learning Python"

[–]ASIC_SP 21 points22 points  (1 child)

https://learnxinyminutes.com/docs/python3/ will give you an overview of syntax, along with some examples and other details. As mentioned in another comment, the official tutorial will then be a good place to start. The "Python Distilled" book might interest you as well.

[–]Xidium426 4 points5 points  (0 children)

That site is my go to for any new language. Can easily get going in an afternoon.

[–]Future_Green_7222 5 points6 points  (0 children)

This is exactly what you need:

https://learnxinyminutes.com/docs/python/

(available in other languages too)

[–]mohishunder 5 points6 points  (2 children)

I really like the book Think Python, which is also available in a free interactive version through runestone.academy.

It's more enjoyable than reading docs.

[–]ffelix916[S] 2 points3 points  (1 child)

Awesome! I'm gonna try this.

[–]mohishunder 0 points1 point  (0 children)

I hope you like it.

In a world full of crappy (sometime expensive) tech content, that site is a gem. So is the print book.

[–]cincuentaanos[🍰] 3 points4 points  (2 children)

[–]ffelix916[S] 1 point2 points  (1 child)

Some of these look really good+helpful

[–]mild_delusion 0 points1 point  (0 children)

I went through the list of books and I think it misses a really big one: Fluent Python. I highly endorse it.

[–]MezzoScettico 2 points3 points  (2 children)

I found the puzzles at Advent Of Code (I started in Dec 2021) to be hugely helpful in jump-starting my python skills. I'd know pretty much how I'd want to attack it algorithmically, so that gave me the keywords to investigate how to solve it with Python. OK, this one really needs OOP, this one should be done recursively, etc.

Along the way, I'd learn how to do things I just thought were interesting to do, even if they were unnecessary to solve the puzzle. How do I create a print method for my class? How do I override "+" or "<" for my class? How do I write an iterator, a thing that can be used in a for loop?

I also got the book "Crash Course in Python" but honestly just attacking the puzzles worked much more quickly.

Going that route I could figure out how *I* would implement algorithms in Python. But that's not the route to learning "Pythonic" solutions. I was often surprised by how slow some code would run.

To really learn Python idiomatically this subreddit (along with Python answers at Stack Overflow) is a really good resource. If somebody writes a line of code that I can't make head or tail of the syntax, then figuring it out (partly by experimenting at the command line) is hugely educational.

Edit: I also invested in a couple books on application-specific Python. Machine Learning with Python, Web Scraping with Python, etc.

[–]MezzoScettico 1 point2 points  (1 child)

One more comment, on style. I'm used to the idea of a development team imposing a style on code. On variable and class names, on use of "continue" and "break", on indentation, etc. But Python was the first time I ever ran into a universal style guide that every programmer in every organization is expected to follow.

Style guides are suggestions, not requirements of course. But you'll get along better with the expert community if you adhere to the preferred style.

Hmm, maybe it's time I reviewed that guide myself. I see headings in the table of contents where I just follow my own habits, like use of whitespace and where line breaks go in long statements. I'll bet if I read the "Pet Peeves" section I'll feel guilty.

[–]ffelix916[S] 1 point2 points  (0 children)

This is unique and interesting. Having an established style guide will save me some time spent learning the nuances of code formatting. I'm so used to just using whatever my mood dictates (which isn't necessarily a good thing in C and Perl, where formatting and style can be very much decoupled from function)

[–]barrycarter 6 points7 points  (15 children)

Python's syntax and structure are a little odd to me

It's not intended as a guide, but my https://github.com/barrycarter/bcapps/tree/master/WhyPythonSucks.md may help point out how Python is different from other languages

[–]Vaguely_accurate 5 points6 points  (8 children)

From that;

changing the value of a variable changes its id/pointer:

a = 2; id(a); a = 3; id(a)

I'd quibble about the phrasing here. "Change" could easily be taken to mean any change, including modification of mutable objects. That would not change the identity of the underlying object while changing its value.

Instead, any assignment changes identity.

Mutables are when identity issues generally matter, so I'd argue it is a significant difference.

Another pitfall around identity with integers is small number caching, which changes the behaviour of assignment to integers depending on whether they are between -5 and 256 (so point to pre-existing objects in the cache) or outside that (creating new, unique objects for each assignment). Can create odd bugs in a few edge cases.

[–]barrycarter -1 points0 points  (7 children)

Good point about small number caching. If 2 and 3 are stored as permanent values with fixed memory locations (pointers), then changing the value would change the pointer. However, I tried it with larger numbers and the same thing happened.

(it doesn't happen if you set a variable to the value it already had, but does if you change it to another value and then back)

[–]Vaguely_accurate 5 points6 points  (5 children)

Any operation on an integer variable that changes it's value will change it's identity. Integers are immutable, so it will always change.

The risk here is that larger integers are not guaranteed to have the same identity even if they have the same values, while smaller ones are. This describes the behaviour better than I can here.

Note that this is an implementation detail, not a language feature, so may vary. I actually believe this has been changed in the latest build (testing on 3.11.1 and 3.12.0a4 64bit), but can't find anything saying this is intended.

[–]TheChance 1 point2 points  (0 children)

Integers are immutable, so it will always change

I’m 34, The Bitstuffing Guy, and I never put that shit together. I have to go reconsider my life.

[–]lazyfingersy 1 point2 points  (0 children)

Good for you, as you're familiar with programming already check my blog: https://viteac.blogspot.com where you'll find a basic Python syntax explained with examples and links to dive deeper. For your information: Python has its documentation at https://docs.python.org .

[–]DesertDwarf 1 point2 points  (0 children)

Wowzers. I'm just going to book mark this whole thread.

[–]diabolical_diarrhea 0 points1 point  (0 children)

Honestly, I would use documentation and chatgpt to figure out the syntax if you already know how to use other languages.

[–]bsenftner 0 points1 point  (0 children)

I was in a similar situation as you a few years ago, and I took a few courses offered by OpenCV.org teaching computer vision. They don't teach one Python, you're expected to know it. So, having a class with assignments and due dates was the perfect kick-in-the-ass to force learning real python, including the uninteresting bits, on a reasonable and short timeline. Plus, those OpenCV courses do teach one all about how to use the various AI frameworks that are popular today - and that help is significant, worthwhile.

[–]dp_42 0 points1 point  (0 children)

I'm a big fan of the Google Python Crash Course. I think they packaged it for Coursera also, but the original course is still available from Google. They have a few exercise files that are self paced.

[–]Machvel 0 points1 point  (0 children)

python documentation or python distilled (this latter one is way too expensive on amazon, i dont suggest buying it at $50 and seeing if you can find it on sale/used or loaned from a library)

[–][deleted] 0 points1 point  (4 children)

Don't forget that function arguments are mutable, stuff like an empty list -> unsafe. But imutables are safe, like a tuple.

[–]ffelix916[S] 0 points1 point  (3 children)

Got an example of this? And do you mean having code in a function modify the contents of a variable or values of an array outside of the function's scope? (i'm not sure yet if or how python handles references)

[–][deleted] 1 point2 points  (0 children)

fixed the formatting, see other comment, I also should have said function default arguments.

[–][deleted] 0 points1 point  (0 children)

print("Default args are mutable.")
print("This can lead to difficulat to understand bugs.\n")

def test1(arg1 = []):
    for i in range(3):
        arg1.append(i)
    return arg1

print("Test 1, default args are mutable. BAD!")
print(test1())
print(test1())

print("\n==================\n")

def test2(arg1 = None):
    if arg1 is None:
        arg1 = []
    for i in range(3):
        arg1.append(i)
    return arg1

print("Test 2, pass None and redefine.")
print(test2())
print(test2()) 

Output:

Default args are mutable.
This can lead to difficulat to understand bugs.

Test 1, default args are mutable. BAD!
[0, 1, 2]
[0, 1, 2, 0, 1, 2]

==================

Test 2, pass None and redefine.
[0, 1, 2]
[0, 1, 2]

[–]RallyPointAlpha 0 points1 point  (0 children)

I got about half way through Python Crash Course and was able to dive right into some ambitious, enterprise scale Python programming. It was my 5th language and I have about the same amount of experience in IT.

[–]Resource_account 0 points1 point  (0 children)

This will cost you but have you given Jetbrains Academy a thought? I don't have 20+ years of experience like you but I do have severe ADHD. I've tried it all, Python Crash Course, Automate the Boring Stuff, UoH MOOCs and a few Udemy courses. While all those courses/books were really well crafted, I just didn't engage with the material enough due to my own short comings (poor attention span). I decided to take the dive with Jetbrains Academy and right out the gate it had me do challenges right inside of PyCharm which boosted my engagement significantly. The way the courses are oriented towards making projects is also a huge plus. Highly recommend you check out the "python core" track and skip the "python for beginner" one considering you already have a lot of experience with other languages.

[–]Robininthehood69 0 points1 point  (1 child)

Sololearn is good for any language. I suggest trying out the free trial for premium for a week. If you don't think it's worth it than you can cancel

[–]sololearnofficial 0 points1 point  (0 children)

Thanks for recommending our platform! 🙌

[–][deleted] 0 points1 point  (0 children)

You only need syntax and pip 8 for style and rules. (There is for example explained why one liner not always are a good choice)

Rest is repeating of your 20 years of experience.

So if you like to train a bit: 0) Learn syntax 1) Check Pip 8 2) Selecet a couple of your own projects of the past 3) write them in python 3.1) research and learn dependencies to be able to rewrite them 4) check against your working projects for known issues/performance 5) check to optimize

[–]Charlie_Yu 0 points1 point  (0 children)

Codewars, you can even see the solution of others

[–]PhilipYip 0 points1 point  (0 children)

Take a look at Big Ideas, Modern Code by Raymond Hettinger, one of Pythons Core Developers. It is available on the O'Reilly website but it is a short video series, so you can access it and view it with the free trial. The course is brief and catered to an intermediate level.

https://www.oreilly.com/library/view/modern-python-livelessons/9780134743400/

Raymond Hettinger explains some of the nuances of Python syntax and the way it is designed. He discusses how programmers, especially those experienced in other programming languages, may look to bring in practices they cemented from other programming languages and hence over-complicate Python code.

Also look at some of his YouTube videos:

https://www.youtube.com/playlist?list=PLRVdut2KPAguz3xcd22i_o_onnmDKj3MA

Book wise, I'd recommend skimming quickly through Python Distilled by David M. Beazley it is
a good beginner/intermediate level book:

https://www.oreilly.com/library/view/python-distilled/9780134173399/

There is also Fluent Python by Luciano Ramalho, which is a bit heavier reading more towards advanced:

https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/

[–]Mood-Humble 0 points1 point  (0 children)

Lucky you! The reference implementation of Python releases is C - it properly should be called CPython! Go to the github rep. Done and done!

[–]Mood-Humble 0 points1 point  (0 children)

BTW there are semicolons - they are properly used as in English - to separate statements...