Single quote only for characters #731
Locked
david-ragazzi
started this conversation in
General
Replies: 1 comment 2 replies
-
How about situation in which string contains |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Playing in the JupyterLab, I see single quotes work both single characters and whole strings. Is there a future plan to Mojo follow a more strict use for single quote delimiting it to represent only characters like most system languages like C/C++, Rust, etc? For instance:
var my_string = String("ABCDEF")
my_string[0] = 'X' # Single quote would be only for character type
my_string[1] = "Y" # Error here
The last row will raise an error because compiler will interpret "Y" as a string, not a character as required by string's set_item() method.
This also would remove ambiguity where code use both single and double quotes to represent strings and characters. Instead of:
var str1 = "Some string"
var str2 = 'Another string'
var ch1 = "A"
var ch2 = 'B'
we would have:
var str1 = "Some string"
var str2 = "Another string"
var ch1 = 'A'
var ch2 = 'B'
PS: Yes, I know PEP states that you can use both, but maybe it's time to modernize PEP to uniform the representation of strings.
Beta Was this translation helpful? Give feedback.
All reactions