LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2015, 09:49 PM   #1
G-Known
LQ Newbie
 
Registered: Jul 2013
Location: New York
Distribution: FreeBSD 11.2-release p9
Posts: 25

Rep: Reputation: Disabled
python isn't displaying the values for assign operators


I'm curious as to why it isn't showing the value of this operation. This is a Slackware 14.1 machine.
Attached Thumbnails
Click image for larger version

Name:	Screenshot - 11232015 - 06:19:05 PM.png
Views:	23
Size:	26.6 KB
ID:	20133  
 
Old 11-26-2015, 12:41 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,222

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Because you're assigning the value to zhong. Enter "zhong" in the next line and you'll see it.
 
Old 11-26-2015, 10:14 PM   #3
G-Known
LQ Newbie
 
Registered: Jul 2013
Location: New York
Distribution: FreeBSD 11.2-release p9
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Because you're assigning the value to zhong. Enter "zhong" in the next line and you'll see it.
But when I try to use this operator like "+=", it doesn't display the result.
 
Old 11-27-2015, 01:49 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
yes, you entered a command and that was executed. Why do you expect anything else?
 
Old 11-27-2015, 09:25 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Python's assignment operators aren't like C's, they don't return a value.
 
Old 11-27-2015, 09:53 AM   #6
G-Known
LQ Newbie
 
Registered: Jul 2013
Location: New York
Distribution: FreeBSD 11.2-release p9
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Python's assignment operators aren't like C's, they don't return a value.
I see, but here's a screenshot that does return the value. So is there something strange?
Attached Thumbnails
Click image for larger version

Name:	python2.png
Views:	17
Size:	38.7 KB
ID:	20144  
 
Old 11-27-2015, 10:51 AM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by G-Known View Post
I see, but here's a screenshot that does return the value. So is there something strange?
No, the screenshot shows that the assignments didn't return the value.
 
Old 11-27-2015, 12:26 PM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,222

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Code:
a = 1  # does not return a value
a = a + 1  # does not return a value
a += 1  # equivalent to a = a + 1 and does not return a value
a  # does not+return a value
Clearer?

Last edited by dugan; 11-28-2015 at 12:40 PM.
 
Old 11-28-2015, 10:19 AM   #9
G-Known
LQ Newbie
 
Registered: Jul 2013
Location: New York
Distribution: FreeBSD 11.2-release p9
Posts: 25

Original Poster
Rep: Reputation: Disabled
Yeah, thanks for the clarification.
 
Old 11-28-2015, 10:21 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
hm. dugan? probably you mistyped, the last command, when you entered nothing but a variable will return the value.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to assign null values to an array in C++ newinubuntu Programming 5 05-08-2015 12:35 PM
[SOLVED] changing variable values with unary vs arithmetic operators atlantis43 Linux - Newbie 9 05-15-2013 09:05 PM
assign vaiables from string values tsdjim Programming 3 03-15-2013 03:19 AM
Python dict query and assign values problems ArthurHuang Programming 2 03-13-2012 04:18 AM
Shell script that assign's values to fields NsearchOf Programming 16 06-01-2009 10:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration