0

Are blank spaces allowed for a variable name? If not then why?

For example, area of a circle and areaofacircle. Which one is correct?

26th Oct 2017, 7:34 AM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar
3 ответов
+ 6
Blank spaces are special character used as separator, so variable names cannot contains any... However, as suggested by the filename example of @luka, fake blank spaces could be part of a variable name through the use of the underline sign ('_'). The other usual way to use variable names with much more pseudo-separated words is the "camel case" notation, where each new words composing the variable have its first letter uppercased: forty_two = 42 fortyTwo = 42 Are both valid variable names... Anyway, this restriction of no blank space use for variable (or function) names, is less strict for hashmap (dictionaries) list, where key is quoted, so the string used as key can hold blank spaces (keys are not real identifier, but string object -- or object first converted to their string repesentation before be used as a key): myDict = {"forty-two is valid":42} print(myDict["forty-two is valid"]) Well, in last example I intentionnally also include a minus sign ('-') wich is no more allowed to form variable names, as obviously it's used as subtract operator ^^
26th Oct 2017, 11:32 AM
visph
visph - avatar
+ 1
Blank characters are special characters used as separators...Thank you very much @Visph for this very useful answer 😊☺
27th Oct 2017, 9:56 AM
Sri Lakshmi
Sri Lakshmi - avatar