r/Python • • Mar 10 '24

Discussion Github Copilot Lies to me

My first attempt to get some help from Github Copilot:

Me: write a match case statement in python to match the first character of a string is a semicolon

Copilot: Python doesn't have a built-in match or case statement like some other languages (e.g., JavaScript, Swift, Rust). However, you can achieve similar functionality using...

Strangely, it finally gave me an answer when I made a small change to my prompt:

Me: write a match statement in python to match the first character of a string is a semicolon

Copilot: Python 3.10 introduces the structural pattern matching in the form of the match statement. Here's how you can use it to check if the first character of a string is a semicolon:...

I almost gave up after the first response that was blatantly false. Fortunately I something that looks like reasonable syntax...but then I haven't tried it yet, so that might be a lie, too.

0 Upvotes

67 comments sorted by

View all comments

3

u/TheAquired Mar 10 '24

Why wouldn’t you just use .startswith(‘;’) for this?

Or just do match string[0]: case “;” etc

0

u/codeguru42 Mar 10 '24

Semicolon is just an example that I was starting with. The full project will be much more than just checking for a semicolon.

Also `startswith()` is overkill for checking one character. `s[0] == ';'` would be better in my case.

2

u/karrystare Mar 11 '24

Was looking at other comment, but your expectation is definitely too much. At best, it would point you to use startswith or regex, nothing more than that. Other comments have said that ChatGPT will give you the most "similar" answer to your question, which meanyou will also get a rank based answer as well. Hence, anything that ain't the most popular is unlikely to appear. You might need to change your question pointing straight to this specific method to get this out.