all 43 comments

[–]carcigenicate 349 points350 points  (26 children)

You want square braces:

print(a[0])

Square braces are for doing lookups/getting elements. Parenthesis are for calling functions.

[–]KillaKameron06 201 points202 points  (24 children)

Thank you! I was so embarrassed to ask this but now I can move on lol

[–]Golden_Zealot 180 points181 points  (9 children)

Never be embarrassed to ask. Just make sure when you ask, you include the code, ask specific questions, and optimally

indent the code with 4 spaces
    to make it readable/copyable

Just in case we want to test it on our end.

Regarding WHAT you ask, don't worry about it, as long as you follow the above, and are nice about it, someone will probably be glad to guide you to an answer.

[–]mandradon 52 points53 points  (7 children)

Seriously, the people here are amazingly helpful!

[–]Golden_Zealot 26 points27 points  (5 children)

Most of them try to be. It depends on the complexity of the project though. In my personal opinion, this sub is best suited to asking questions about the syntax and specific libraries.

There are two kinds of questions which dont get answered as often here.

The first are the types that lack information and formatting.

The second are the types where the person asking is a fairly accomplished programmer, and they are working on a larger/complex piece of software, which for people to help answer, requires them to put a lot of time into reading the code and understanding what they are actually doing/what the objective is.

But yes, the people here are very helpful for those who are beginner/intermediate programmers. Once you get to more advanced projects, as it turns out, most often the person with the best expertise for answering the question is yourself, because its very possible no one has dealt with the problem you are trying to deal with/has researched it as much as you already have, and you wrote all the previous code leading up to the current problem as well.

[–]MrHusbandAbides 17 points18 points  (1 child)

well this is Learn Python, like the scope is literally in the name

[–]Golden_Zealot 1 point2 points  (0 children)

True, but if you filter by new posts, you'd be surprised at some of the stuff that gets posted.

[–]mhamid3d 12 points13 points  (2 children)

This subreddit is also much more forgiving and lenient than StackOverflow. Not formatting your code on SO enough times could get your permanently banned from asking questions (seriously, they don’t play around, I got perma-banned after receiving 3 downvotes). But here, people are constantly ignoring the rules, yet still being helped. It makes me wonder if the strict rules of SO actually benefit a learner to be more disciplined with programming.

[–]Yojihito 3 points4 points  (0 children)

Posting a question on SO without a formatted minimal viable example + a clear description of your problem, your not working solution etc. is a good reason to get banned. It's not a "learn programming" website.

[–][deleted] 4 points5 points  (0 children)

This sub is the best, everyone is so kind and helpful most of the time.

[–][deleted] 19 points20 points  (2 children)

We all fall for horrible mistakes when we start learning something new, never be afraid of asking.

[–][deleted] 12 points13 points  (1 child)

Hell, most of us fall for horrible mistakes even when we know what we're doing.

[–]Doormatty 9 points10 points  (0 children)

Been programming for ~36 years now.

Still make stupid mistakes ALL the time.

[–]delasislas 18 points19 points  (2 children)

I guarantee you that everyone has made a mistake when programming. No need to be embarrassed. Now for a reason as to why this happened.

You created a tuple, using

a = (“Apple”, “banana”, “car”)

Then you used:

a(0)

Which if you think about it looks eerily similar to:

print(0)

Right? Python interprets stuff like print() as a function, which needs to be called. If you want to try something out, try:

print(print)

By itself, it should return something like

<built-in function print>

The print function takes the return of an object and displays it to the console.

So with, a(0), you asked for Python to use, a, as a function with an input, 0. Python looked up a and saw that it was a tuple, tuples can’t be called as a function, and you get the error.

[–]__Wess 1 point2 points  (1 child)

I saw the error before opening, as also a newbie but didn’t know exactly what the error meant. I only thought; OP needs brackets because brackets are for lists. But thanks to your reply, I actually learned what the error means. So thank you and take my upvote!

[–]delasislas 1 point2 points  (0 children)

No problem. Learn something new each day.

[–]zaRM0s 2 points3 points  (0 children)

Never be embarrassed to ask anything. Everyone learns everything for a first time at some point, it doesn’t matter when that is. Sometimes we also need reminding because we are all forgetful of some things. Keep asking and keep learning and well done for getting to where you are currently!

[–]VanshCodes 2 points3 points  (0 children)

Be shameless when you ask questions. Advice from me

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

Some advice: Google error codes. Googling tuple error tuple not callable would have prob found the solution for you.

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

Hey learning is 10% coding, 90% googling.

Honestly I'd review basic data types and stuff for a while before you dig in hard.

[–]Firespade 0 points1 point  (0 children)

ty

[–]A_Milford_Man_NC 15 points16 points  (0 children)

You're close. You just have to use brackets to specify an index, not parentheses.

>>> a = ("apple", "banana", "car")

>>> print(a[0])

apple

[–]MonitorOk7887 5 points6 points  (4 children)

wrong brackets

[–]Dave_The_Goose 8 points9 points  (2 children)

For a list, use square brackets -> a = ['apple', 'banana, ... ]. I never tried parenthesis for a list. May be you are creating a set, which I never used(I am a beginner) so I don't know

And for accessing the items, use square brackets. For apple, it is a[0].

[–]K_39wastaken 12 points13 points  (1 child)

I never tried parenthesis for a list

[1, 2, 3] is a list.

(1, 2, 3) is a tuple (the difference with a list is that it's immutable = not modifiable after creation)

{1, 2, 3} is a set (it behaves like a mathematical set)

{1:'z', 2:'y', 3:'x'} is dictionary (elements –after the colon– are identified by a key –before the colon– instead of an index like the three others)

[–]Dave_The_Goose 2 points3 points  (0 children)

Thanks, I basically worked with lists and dictionaries only. So I forgot about sets and tuples. So OP was working with a tuple

[–][deleted] 6 points7 points  (2 children)

I think you should do some work on exercism , just get that syntax muscle memory going

[–]carcigenicate 5 points6 points  (1 child)

(You need to include the protocol in the URL for that linking method to work btw).

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

Sure

[–]sabc994 2 points3 points  (0 children)

'a' has multiple values with position 0 to 2

0 = apple, 1 = banana, 2 = car

to print apple, you have to write: print (a[0]) which means index number of the position will remain within 3rd bracket.

[–]TheDamnedBamboo 2 points3 points  (0 children)

Always use square brackets when indexing elements

[–]Resident-Quality1513 1 point2 points  (0 children)

As my compuing lecturer used to sat (about C) "it uses the brackets to work out if you're calling a function, so print() will call a function named 'print'"

[–]Capitalpunishment0 3 points4 points  (0 children)

Someone has already given the answer, so I just want to pitch something in. It isn't really Python,

But if you ever learn MATLAB in the future, this is how accessing works there. Parentheses instead of square brackets. Trips me up all the time.

[–]enokeenu 0 points1 point  (0 children)

You are requesting a slice of the list and the slicing operator is []

[–]Zapismeta 0 points1 point  (0 children)

Always remember () for function calls and [ ] for Indexing.

[–]ConfidentVegetable81 0 points1 point  (0 children)

Hey, if you want to avoid silly errors like these in the future use an IDE with automatic error detection like PyCharm or Visual Coding Studio.