Which of the following are valid identifiers and why/why not:
(i) Myfile (ii) 29CLCT (iii) DATE9_7_77
(iv) break (v) $1_to_$10
Answers
Answered by
4
ɧɛƖƖơ ɱąɬɛ
Qᴜᴇsᴛɪᴏɴ:
ᴡʜᴀᴛ ᴀʀᴇ ᴛʜᴇ ʀᴜʟᴇs Fᴏʀ ᴀɴ ɪᴅᴇɴᴛɪFɪᴇʀ ᴛᴏ ʙᴇ ᴠᴀʟɪᴅ ??
ᴀɴsᴡᴇʀ:
- ᴛʜᴇ Fɪʀsᴛ ᴄʜᴀʀᴀᴄᴛᴇʀ ᴍᴜsᴛ ʙᴇ ᴀ ʟᴇᴛᴛᴇʀ (ᴇɪᴛʜᴇʀ ᴀ-ʙ ᴏʀ ᴀ-ʙ).
- ɪᴛ ᴄᴀɴ ᴀʟsᴏ sᴛᴀʀᴛ ᴡɪᴛʜ ᴜɴᴅᴇʀsᴄᴏʀᴇ( _ ) .
- ᴅɪɢɪᴛs ᴄᴀɴ ʙᴇ ᴀ ᴘᴀʀᴛ ᴏF ᴀ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ʙᴜᴛ ᴀɴ ɪᴅᴇɴᴛɪFɪᴇʀ sʜᴏᴜʟᴅ ɴᴏᴛ sᴛᴀʀᴛ ᴡɪᴛʜ ᴀ ᴅɪɢɪᴛ.
- ᴀ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ᴅᴏᴇs ɴᴏᴛ ʜᴀᴠᴇ ᴀɴʏ sᴘᴇᴄɪᴀʟ ᴄʜᴀʀᴀᴄᴛᴇʀ ᴏᴛʜᴇʀ ᴛʜᴀɴ ᴜɴᴅᴇʀsᴄᴏʀᴇ ( _ ).
- ᴀɴʏ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ᴍᴜsᴛ ɴɪᴛ ʙᴇ ᴀ ᴋᴇʏᴡᴏʀᴅ ᴏF ᴘʏᴛʜᴏɴ.
Qᴜᴇsᴛɪᴏɴ:
ᴡʜɪᴄʜ ᴏF ᴛʜᴇ Fᴏʟʟᴏᴡɪɴɢ ᴀʀᴇ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀs ᴀɴᴅ ᴡʜʏ/ᴡʜʏ ɴᴏᴛ:
ᴀɴsᴡᴇʀ:
(i) Myfile → valid
ʀᴇᴀsᴏɴ :
(follows all the rules mentioned above)
_______________________
(ii) 29CLCT → invalid
ʀᴇᴀsᴏɴ :
(starts with a digit )
_______________________
(iii) DATE9_7_77 → valid
ʀᴇᴀsᴏɴ :
(follows all the rules mentioned above)
_______________________
(iv) break → invalid
ʀᴇᴀsᴏɴ :
(python keyword)
_______________________
(v) $1_to_$10 → invalid
ʀᴇᴀsᴏɴ :
(have a special character ($))
_______________________
ɧơ℘ɛ ıɬ ɧɛƖ℘ʂ ყơų ☺
Answered by
0
Answer:-
(i) Myfile
(ii) DATE9_7_77
(i) 29CLCT
must not begin with a digit.
(ii) break
A keyword cannot be used as an identifier.
(iii) $1_to_$10
Only special character allowed is undercore ; $ not allowed.
✨
Similar questions