#π printing the wrong thing..?
65 messages Β· Page 1 of 1 (latest)
@magic aurora
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
im a beginner btw
fruits = ["apple", "banana", "orange"]
print(fruits)
print(fruits[1])```
hmm making it 0 seems to work
yeah 0 is the first index
yeah, in programming you count from 0 up
idk in lua its 1
luas index are better
cuz 0 is the placeholder for nothing
basically nil
i dont know lua
But this is python, and we have something similar. None
but most of the time they count by 0
:o
0 is because it's the offset from the first element
so array[0] means offset 0 from first item which means first item
so it calculates the offset to first item instead of counting the items
It was because of how C designed it from a pointer
Yes
-1 wraps it around to the end of the list bc of this as well
i hope i get used to this cuz i cant use lua if i want to get a job later
Most programming languages use this offset system as well, so I'd say getting used to it is better in the longer term
I think over 70% of the programming languages start with 0 because of how binary works. Correct me if I'm wrong π
yeah I would say that
do they use none instead of nil too
in python None I would say is equal to nil
nil and None are essentially the same, yes
in python you also dont need to specify the type of a variable
has its disadvantage but also an advantage
thats a downside for me
i like writing something before the variables it makes it easier to read imo
You can specify the type, itβs just not going to throw an error if you change its type
Var: int = 20
type annotations are primarily for IDEs, they will yell at you if you type things wrong
There are tools to help you with it, pylint is famous for checking typehinting for you
There are also tricks to check during runtime, but generally it's not worth the effort - it's more of a design problem
Python has a huge advantage and that's its development speed
Not having to define static type is a boon and a problem at the same time, but if you pick python for the speed of development, it's a boon
yeah of course I say it because in other programming language maybe you need char a = ... long number = .....
luaify
the interpreter does define the types I guess
The interperter will "guess" the type based on what you do, for example
number_str = input(...)
number = int(number_str) # interpreter will guess this is an int```
The type will be defined much later when it's being translated
ok yeah thats why many people say python is very slow from what I heard
what if the user inputs a string
input returns a string
It will raise a ValueError if you call int() on a string that's not convertible
python is slow, but that's when it comes to extreme computing and/or IO heavy tasks
--> str
For better or worse, if it comes to that you might have picked the wrong tool for the job
But there are always ways to improve performance, I'll worry about it least
number_str is the name I give to the value given back from input() - to signify that it's indeed a string and not a number yet
yeah of course python good for beginners cause C is really close to assembly
python is a high level programming language, which means you do not have to worry about low level concepts like managing pointers / memory usage/address
For beginners these concepts are very hard to understand at first
yeah thats it but keep in mind high needs to translate to low
The reason indexes start from 0 is because it's actually a memory offset.
so you're doing memory_location + (index * object_size)
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
π printing the wrong thing..?