Is Python much like PHP in that I can call a variable and if it doesn’t exist it will be created? Or I need to declare them?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In PHP if you call a variable and it doesn’t exist, you’ll get
Notice: Undefined variable. This doesn’t create it — doing the same thing again still returns a warning.In Python if you call a variable and it isn’t initialized you’ll get a
NameError. Same thing – it won’t get created – you’ll getNameErroruntil you actually initialize it.Initialization without declaration:
In both PHP and Python though, unlike say, C, you don’t need to declare the variables before first using them, and that’s perhaps what you meant. You can just assign them and they’ll be created on first assignment.