LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-04-2004, 08:06 PM   #1
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Rep: Reputation: 30
python cant assign to literal


hello would some one mind explaining to me why i get the error message
"SyntaxError: can't assign to literal"
if i type
>>> q = 7
>>> print q
7
thats fine, but why can i not do it the other way around ie
"7 = q"
thank for all the replys i am sure to get in advance
nige
 
Old 09-04-2004, 10:49 PM   #2
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
The variable name is always on the left-hand side. That is what gets assigned to. 7 is a literal number and can't be assigned to.
 
Old 09-05-2004, 01:54 PM   #3
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
cheers buddy
 
Old 09-05-2004, 04:29 PM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Just a minor clarification: in most programming languages, the "=" operator behaves differently than it does in mathematics. In math, it doesn't matter if you say "x=5" or "5=x", since what you're expressing is an equivalence - you're saying that those two things have the same value. In programming languages, you're asking for a value to be assigned to something - in particular, you're asking for the value on the right to be assigned to the variable on the left. The use of "=" is slightly unfortunate, since a better operator might look like this:

Code:
x <- 5
Since the value of "5" can't be changed, it's a syntax error to do it the other way around.
 
Old 09-05-2004, 04:36 PM   #5
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
wapcaplet
Guru
very well put thank you it makes a lot more sense now
nige
 
  


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
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
How do you set a shell script var with a literal '*'? BrianK Programming 3 06-22-2004 02:11 PM
How do you write binary literal constants in C? vasudevadas Programming 5 01-18-2004 07:39 AM
Using letters/strings to assign variables in python Colonel Panic Programming 0 09-14-2001 10:13 PM

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

All times are GMT -5. The time now is 06:22 PM.

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