Python Forum
variable prints without being declared.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable prints without being declared.
#1
I'm a beginner new to this site and I don't know if this has been posted before, so please be patient with me.
This isn't an error in as much as I'm curious. I declared a variable with the print function.

var = print("Hello")
It printed even without me calling the variable. Why is that?
Reply
#2
var is not printing, the str "Hello" is printing. The value of var is None because that is the value returned by the print function.
ClockPillow likes this post
Reply
#3
(Jul-11-2021, 12:05 AM)deanhystad Wrote: var is not printing, the str "Hello" is printing. The value of var is None because that is the value returned by the print function.

Thanks for that. I figured it out thanks to you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  zfill prints extra et the end of a var tester_V 4 908 Mar-24-2023, 06:59 PM
Last Post: tester_V
  Output prints Account.id at the end? LastStopDEVS 5 2,794 Dec-19-2020, 05:59 AM
Last Post: buran
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 2,368 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov
  Try/Exept prints only ones tester_V 11 3,896 Nov-03-2020, 02:38 AM
Last Post: tester_V
  loop only prints last character. mcmxl22 1 1,730 Feb-17-2020, 02:36 AM
Last Post: menator01
  Binding not explicitly declared happening karkas 4 2,870 Aug-05-2019, 05:09 PM
Last Post: karkas
  zip file variable prints <zipfile.ZipFile object at 0x7f83fd13bd90> ? Rsh 9 4,160 Jun-27-2019, 02:00 PM
Last Post: Rsh
  can you understand why this code prints None? arcbal 2 2,762 Mar-13-2019, 02:57 AM
Last Post: arcbal
  What for a file that prints nothing sylas 1 2,183 Sep-12-2018, 01:18 PM
Last Post: gruntfutuk
  How to call a variable declared in a function in another python script lravikumarvsp 2 2,941 Jun-04-2018, 08:45 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020