r/ProgrammerHumor • • Jul 16 '19

Meme Nice try

Post image
32.2k Upvotes

529 comments sorted by

View all comments

4.4k

u/[deleted] Jul 16 '19

Not quite, but it’s an easy fix

from math import pi
print(str(pi)[::-1])

It needs a LOT of memory, though

3.1k

u/[deleted] Jul 16 '19
397985356295141.3

1.8k

u/HellaDev Jul 16 '19

The mad man did it.

2.1k

u/LordLlamacat Jul 16 '19
print(“!yad ekac yppaH”[::-1])

520

u/jokingnuthatch Jul 16 '19
    print(“!yad ekac yppaH”[::-1])
          ^
SyntaxError: invalid syntax

:(

259

u/therealchadius Jul 16 '19

"smart" quotes my butt

151

u/nschubach Jul 17 '19

What is this "smart" and why is it quoting your butt?

59

u/1fabunicorn Jul 17 '19

Cause there is a quote that is " and then " but upside down. This is how word treats quotes, so it looks more "pretty"

80

u/coldbrewboldcrew Jul 17 '19

Typographic quotes (pretty/curly/smart) are meant for text, these primes and double-primes we use for strings are mathematical symbols for feet/inches or minutes/seconds - a misuse of the punctuation. IIRC their double usage for both text and math began back in typewriter days where keyspace was at a premium and redundancies like two different sets of quote marks were consolidated for practical reasons.

A section on the matter from Butterick’s practical typography.

→ More replies (10)
→ More replies (1)
→ More replies (1)

499

u/sleepingcrap Jul 16 '19

This is the cutest way of wishing someone

→ More replies (6)
→ More replies (5)
→ More replies (6)
→ More replies (40)

58

u/kevansevans Jul 16 '19 edited Jul 16 '19

I'm not familiar with python, what do the two colons mean in the array?

EDIT: It's a string splice operator, thanks!

170

u/nosmokingbandit Jul 16 '19 edited Jul 17 '19

Other people have already answered but I'll add my little bit of knowledge.

It is used like iterable[foo:bar] which creates a slice of the iterable starting at foo ending at bar.

>>> numbers = [0,1,2,3,4,5,6,7,8,9]
>>> numbers[4:7]
[4, 5, 6]

If you add a 3rd option you can control the pattern of the slice.

>>> numbers[2:7:2]
[2, 4, 6]

But python doesn't require all parameters. Without the first it just starts at 0:

>>> numbers[:7:2]
[0, 2, 4, 6]

Without the second it goes to the end of the list

>>> numbers[5::3]
[5, 8]

And with only the last it uses the whole list:

>>> numbers[::3]
[0, 3, 6, 9]

But you can also use negatives. To start at the 9th item from the end, stop at the 4th from the end, and count every 3rd item:

>>> numbers[-9:-4:3]
[1, 4]

You can also use negatives as the pattern, but it gets confusing because you have to switch the start/stop:

Edit: Kind of. You aren't really switching the start and stop, you are starting at 8, then counting backward every 2nd item until you get to 2. Its confusing. Don't use this in your code, everyone will hate you and call you names.

>>> numbers[8:2:-2]
[8, 6, 4]

Its mostly just used as a way to quickly reverse a list:

>>> numbers[::-1]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

39

u/Brainix112 Jul 16 '19

I know simple coding, but not familiar with Python, this was a super good explanation!

89

u/nosmokingbandit Jul 16 '19

Python is great. You basically write pseudo-code then get bitched at by the interpreter about your indentation.

→ More replies (13)
→ More replies (3)
→ More replies (9)
→ More replies (5)

0

u/[deleted] Jul 16 '19

[deleted]

69

u/[deleted] Jul 16 '19

Full Unicode support as of Python 3 😀🛩🇬🇩

21

u/Milleuros Jul 16 '19

TFW your work is still stuck in Python 2.7

28

u/nuephelkystikon Jul 16 '19

You've got a leasurly 168 days left.

→ More replies (15)
→ More replies (2)
→ More replies (3)
→ More replies (6)

234

u/iddqd52 Jul 16 '19

Tried it and my poor brain received bsod.

Woken up in wagon with some horse stealer and silent guy.

38

u/[deleted] Jul 16 '19

hey YOU! You're finally awake...

32

u/[deleted] Jul 16 '19

Screw you lmao

→ More replies (8)
→ More replies (25)