Can str be used as a variable?
Posted: Wed Feb 02, 2022 2:37 am
I'm just learning python and I decided to take a beginners online quiz to test myself. One of the questions was this:
8. What is the output of the following code?
A. py
B. yn
C. pyn
D. yna
Because of the slice() function the anwer is B. But that's not my question. I thought it was odd that they used "str" as a variable. I wasn't even aware that you could use a built-in function as a variable. I would have thought that at a minimum this is poor coding practice. Am I missing something here?
8. What is the output of the following code?
Code: Select all
str = "pynative"
print (str[1:3])
A. py
B. yn
C. pyn
D. yna
Because of the slice() function the anwer is B. But that's not my question. I thought it was odd that they used "str" as a variable. I wasn't even aware that you could use a built-in function as a variable. I would have thought that at a minimum this is poor coding practice. Am I missing something here?