Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:54:08+00:00 2026-06-02T12:54:08+00:00

Is Python much like PHP in that I can call a variable and if

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:54:09+00:00Added an answer on June 2, 2026 at 12:54 pm

    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.

    php > echo $some_uninitialized_var;
    PHP Notice:  Undefined variable: some_uninitialized_var in php shell code on line 1
    php > echo $some_uninitialized_var;
    PHP Notice:  Undefined variable: some_uninitialized_var in php shell code on line 1
    

    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 get NameError until you actually initialize it.

    >>> print(some_uninitialized_var)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'some_uninitialized_var' is not defined
    
    >>> print(some_uninitialized_var)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'some_uninitialized_var' is not defined
    

    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.

    // PHP
    $a_new_var = 12345;
    // All is well...
    
    # Python
    a_new_var = 12345
    # All is well...
    
    // C
    a_new_var = 12345;
    // Crash! Horror! Compiler complains!
    int a_new_var;
    a_new_var = 12345;
    // ok...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know much python but from what I can tell from the documentation
Much like Java (or php), I'm use to seperating the classes to files. Is
Many people say developing in Python, Ruby, PHP ...etc is much faster than Java.
I love how in python I can do something like: points = [] for
Python needs a framework, so does Java (for the web). I don't know much
I'm just starting on Python and maybe I'm worrying too much too soon, but
Background Python has "textwrap" and "dedent" functions. They do pretty much what you expect
I've been messing around with Python over the weekend and find myself pretty much
I'm a fairly strong Python coder, but too much of my style is a
Are there any tools which generate a project layout for python specific projects, much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.