#๐Ÿ”’ Why is THIS possible?

28 messages ยท Page 1 of 1 (latest)

gilded briarBOT
#

@twilit hamlet

Python help channel opened

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.

dark grotto
#

For strings this would be using the ordinal number

twilit hamlet
#

what's that?

wooden kayak
#

!py

ord("a")
gilded briarBOT
#
System Python

Why Avoid System Python for Development on Unix-like Systems:

  • Critical Operating System Dependencies: Altering the system Python installation may harm internal operating system dependencies.
  • Stability and Security Concerns: System interpreters lag behind current releases, lacking the latest features and security patches.
  • Limited Package Control: External package management restricts control over versions, leading to compatibility issues with outdated packages.

Recommended Approach:

  • Install Independent Interpreter: Install Python from source or utilize a virtual environment for flexibility and control.
  • Utilize Pyenv or Similar Tools: Manage multiple Python versions and create isolated development environments for smoother workflows.
wooden kayak
#

!py

print(ord("a"))
#

err what was the command for that

twilit hamlet
#

So it's just converted to a number?

#

in the ascii table?

high trellis
#

!e

print(ord("a"))
gilded briarBOT
wooden kayak
#

not ASCII exactly, as this works for any unicode character

#

but the idea is the same

twilit hamlet
#

!e

print("What?")
gilded briarBOT
twilit hamlet
#

!e

print([i for i in range(200000000)])
gilded briarBOT
twilit hamlet
#

lol

frigid void
#

it's also relevant to know, that < is used for sorting things.
so if you got a list of names, you can sort it, and internally it's using < to compare each item (by default at least)

#

!e

names = ['sani', 'retopear', 'alice', 'zorro']
names.sort()
print(names)
gilded briarBOT
frigid void
#

!e though because it's using the ordinal value of the letters, it might mess up the sorting, if you have mixed cases of your letters:

names = ['sani', 'retopear', 'alice', 'Zorro']
names.sort()
print(names)
gilded briarBOT
frigid void
#

as all capital letters have a lower ordinal value as their lowercase counterparts

#

you can fix that by using a key:
names.sort(key=str.casefold)

#

๐Ÿ™‚

gilded briarBOT
#
Python help channel closed

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.